About CreateChildControls()

M

mugurel

Trying to implement an composite control, I OverRide CreateChildControls(),
where I add my controls, dinamicaly. I try to ad an
System.Web.UI.WebControls.LinkButton Control, and I have the following ,
error :

Control '_ctl0' of type 'LinkButton' must be placed inside a form tag with
runat=server.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information about
the error and where it originated in the code.


Exception Details: System.Web.HttpException: Control '_ctl0' of type
'LinkButton' must be placed inside a form tag with runat=server.

Source Error:


Line 52: this.Attributes.Add("onmouseover","(window.status=\'" +
this.ToolTip.Replace("'","\'").Replace("\"","\\\"") + "\'); return true");
Line 53: this.Attributes.Add("onmouseout","(window.status=\'\'); return
true");
Line 54: base.Render(writer);
Line 55: }
Line 56: }

Stack Trace:


[HttpException (0x80004005): Control '_ctl0' of type 'LinkButton' must be
placed inside a form tag with runat=server.]
System.Web.UI.Page.VerifyRenderingInServerForm(Control control)
System.Web.UI.WebControls.LinkButton.AddAttributesToRender(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter writer)
System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
WebControlLibrary.LinkButton.Render(HtmlTextWriter writer) in
C:\Inetpub\wwwroot\CALLCAPTURE\CallCapture.root\CallCapture\WebControlLibrary\LinkButton.cs:54
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
System.Web.UI.Control.Render(HtmlTextWriter writer)
System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter writer)
System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
ASP.WebForm2_aspx.__Render__control1(HtmlTextWriter __output, Control
parameterContainer) in c:\inetpub\wwwroot\CallCapture\WebForm2.aspx:11
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
System.Web.UI.Control.Render(HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Page.ProcessRequestMain()


It is necesary to set runat attribute to "server", for all controls created
dinamicaly ?
 
B

Brock Allen

I suspect your Composite Contorl isn't inside page's <form runat=server>
tag. You can have controls outside the <form runat=server> but they can't
be the kinds of controls that induce a postback, such as a LinkButton.
 
M

mugurel

No the control is inside of form.
Here you have CreateChildControls function:

protected override void CreateChildControls()
{
bool last = false;
for(int i = 0; i < text.Count; i++)
{
last = (i == text.Count - 1);

if(last)
{
Label lb = new Label();
lb.Text = HttpUtility.HtmlEncode(text);
Controls.Add(lb);
}
else
{
LinkButton lk = new LinkButton();
lk.Text = text;
Controls.Add(lk);

lk.Click += new EventHandler(lk_Click);

Label lb = new Label();
lb.Text = ">";
Controls.Add(lb);
}
}
}


Brock Allen said:
I suspect your Composite Contorl isn't inside page's <form runat=server>
tag. You can have controls outside the <form runat=server> but they can't
be the kinds of controls that induce a postback, such as a LinkButton.




Trying to implement an composite control, I OverRide
CreateChildControls(), where I add my controls, dinamicaly. I try to
ad an System.Web.UI.WebControls.LinkButton Control, and I have the
following , error :

Control '_ctl0' of type 'LinkButton' must be placed inside a form tag
with runat=server. Description: An unhandled exception occurred during
the execution of the current web request. Please review the stack
trace for more information about the error and where it originated in
the code.

Exception Details: System.Web.HttpException: Control '_ctl0' of type
'LinkButton' must be placed inside a form tag with runat=server.

Source Error:

Line 52: this.Attributes.Add("onmouseover","(window.status=\'" +
this.ToolTip.Replace("'","\'").Replace("\"","\\\"") + "\'); return
true");
Line 53: this.Attributes.Add("onmouseout","(window.status=\'\');
return
true");
Line 54: base.Render(writer);
Line 55: }
Line 56: }
Stack Trace:

[HttpException (0x80004005): Control '_ctl0' of type 'LinkButton' must
be
placed inside a form tag with runat=server.]
System.Web.UI.Page.VerifyRenderingInServerForm(Control control)

System.Web.UI.WebControls.LinkButton.AddAttributesToRender(HtmlTextWri
ter
writer)
System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
WebControlLibrary.LinkButton.Render(HtmlTextWriter writer) in
C:\Inetpub\wwwroot\CALLCAPTURE\CallCapture.root\CallCapture\WebControl
Library\LinkButton.cs:54
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
System.Web.UI.Control.Render(HtmlTextWriter writer)
System.Web.UI.WebControls.WebControl.RenderContents(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
ASP.WebForm2_aspx.__Render__control1(HtmlTextWriter __output,
Control
parameterContainer) in c:\inetpub\wwwroot\CallCapture\WebForm2.aspx:11
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer)
System.Web.UI.Control.Render(HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Page.ProcessRequestMain()
It is necesary to set runat attribute to "server", for all controls
created dinamicaly ?
 
B

Brock Allen

No the control is inside of form.

Do you mean page or server side form? If your Custom Control is really inside
the <form runat=server> tag in the page then I don't know what the error
"Control '_ctl0' of type 'LinkButton' must be placed inside a form tag with
runat=server" means. Sorry.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top