M
matt
hello,
i have a usercontrol in my app that draws a DropDownList and some text.
elsewhere, i have a need to extract the control's HTML as if it had
been rendered in-page.
typically, when i need to do this for ASP.NET controls, i do the
following:
//some control
HyperLink link = new HyperLink();
link.Text = "sometext";
link.NavigateUrl = "http://www.yahoo.com";
//get its HTML
StringBuilder sb = new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
link.RenderControl(htw);
string html = sb.ToString();
however, this technique doesnt seem to be working for my user control:
//my control
Controls.MyControl myControl = new Controls.MyControl();
//get its HTML
StringBuilder sb = new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
myControl.RenderControl(htw);
string html = sb.ToString();
....the var html is always empty.
am i missing something, or doesnt this work for usercontrols?
thanks!
matt
i have a usercontrol in my app that draws a DropDownList and some text.
elsewhere, i have a need to extract the control's HTML as if it had
been rendered in-page.
typically, when i need to do this for ASP.NET controls, i do the
following:
//some control
HyperLink link = new HyperLink();
link.Text = "sometext";
link.NavigateUrl = "http://www.yahoo.com";
//get its HTML
StringBuilder sb = new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
link.RenderControl(htw);
string html = sb.ToString();
however, this technique doesnt seem to be working for my user control:
//my control
Controls.MyControl myControl = new Controls.MyControl();
//get its HTML
StringBuilder sb = new StringBuilder();
System.IO.StringWriter sw = new System.IO.StringWriter(sb);
HtmlTextWriter htw = new HtmlTextWriter(sw);
myControl.RenderControl(htw);
string html = sb.ToString();
....the var html is always empty.
am i missing something, or doesnt this work for usercontrols?
thanks!
matt