Ask a Question related to ASP.NET Building Controls, Design and Development.
-
matt@mailinator.com #1
extracting a UserControl's HTML ?
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
matt@mailinator.com Guest
-
Object reference error in UserControl's Load event
I have a UserControl that I declare programmatically as follows: Dim userctrl as New rightside_portal() The codebehind file for this... -
UserControl's Page_Load firing automatically
Hi I created a default webform and a default webusercontrol with vs2003. I then added the usercontrol to the form and browsed the page. As... -
extracting dlls from cab
Internet Component Download: I've created cab file which must extract a list of dlls to the user's machine. Since there is problem in extracting... -
Extracting HTML source from Javascript
I am trying to use the CFHTTP command to pull HTML source into a variable. The problem I am running into is that the HTML page is using a javascript... -
Extracting web data
Can anyone point me to java packages which aid in parsing web pages? TIA matt -
matt@mailinator.com #2
Re: extracting a UserControl's HTML ?
ok, i believe ive found one mistake:
//my control
Controls.MyControl myControl = new Controls.MyControl();
i think may need to be:
//my control
Controls.MyControl myControl =
(Controls.MyControl)LoadControl("~/myControl.ascx");
but, that gives me a new error:
Control 'ddlReports' of type 'DropDownList' must be placed inside a
form tag with runat=server.
....ddlReports is a dropdownlist w/i my usercontrol. the control is
evidently barfing because it is being asked to render itself directly,
w/o being inside of a server-side <form> tag.
so, what to do? putting a server-side <form> tag inside the control
seems problematic, because i wont be able to place it on any other
webform, since that would produce *two* <form> tags.
additionally, i do not want a <form> tag when i extract this
usercontrol's HTML. (tho i could probably parse it out).
how does one attain this seemingly simple goal of extracting a
usercontrol's rendered HTML...?
thanks!
matt
matt@mailinator.com Guest
-
Anthony Merante #3
Re: extracting a UserControl's HTML ?
I've had the same issue before. My solution was simple because i didnt WANT
the dropdownlist so i had to visible=false those form controls. I agree, you
prolly dont want to add a <form> inside your UC.
I wonder if you could do a
HtmlForm form = new Htmlform();
myControl.Controls.InsertAt(0,form);
Only insert that HtmlForm inside your export function. See if that will do
the trick.
HTH,
T
<matt@mailinator.com> wrote in message
news:1152824930.183537.270560@m73g2000cwd.googlegr oups.com...> ok, i believe ive found one mistake:
>
> //my control
> Controls.MyControl myControl = new Controls.MyControl();
>
> i think may need to be:
>
> //my control
> Controls.MyControl myControl =
> (Controls.MyControl)LoadControl("~/myControl.ascx");
>
>
> but, that gives me a new error:
>
> Control 'ddlReports' of type 'DropDownList' must be placed inside a
> form tag with runat=server.
>
> ...ddlReports is a dropdownlist w/i my usercontrol. the control is
> evidently barfing because it is being asked to render itself directly,
> w/o being inside of a server-side <form> tag.
>
>
> so, what to do? putting a server-side <form> tag inside the control
> seems problematic, because i wont be able to place it on any other
> webform, since that would produce *two* <form> tags.
>
> additionally, i do not want a <form> tag when i extract this
> usercontrol's HTML. (tho i could probably parse it out).
>
> how does one attain this seemingly simple goal of extracting a
> usercontrol's rendered HTML...?
>
>
> thanks!
> matt
>
Anthony Merante Guest
-
matt@mailinator.com #4
Re: extracting a UserControl's HTML ?
Anthony Merante wrote:this does not work, either. same thing, even when i find the control> I wonder if you could do a
>
> HtmlForm form = new Htmlform();
> myControl.Controls.InsertAt(0,form);
from w/i that form object.
MS - is there no way to do this?? how does one get the HTML of a
*usercontrol* that contains server-side controls??
matt
matt@mailinator.com Guest



Reply With Quote

