How do I get the HTML output of a UserControl in .NET (C#)?

后端 未结 7 2041
终归单人心
终归单人心 2020-11-28 05:33

If I create a UserControl and add some objects to it, how can I grab the HTML it would render?

ex.

UserControl myControl = new UserControl();
myContr         


        
相关标签:
7条回答
  • 2020-11-28 06:29

    override the RenderControl method

    protected override void Render(HtmlTextWriter output)
    {       
       output.Write("<br>Message from Control : " + Message);       
       output.Write("Showing Custom controls created in reverse" +
                                                        "order");         
       // Render Controls.
       RenderChildren(output);
    }
    

    This will give you access to the writer which the HTML will be written to.

    You may also want to look into the adaptive control architecture of asp.net adaptive control architecture of asp.net where you can 'shape' the default html output from controls.

    0 讨论(0)
提交回复
热议问题