this.Controls.Add(ImageButton[i]) exception

C

CJ Oakwood

Morning -

I am hoping somebody from this group can help me out here...

I have been trying to add an array of ImageButtons to my WebForm however I
keep getting an exception that I can't seem to find an answer for any where
on the net.

Any help in the right direction would be greatly appreciated. If more
code/source is need please let me know and I will post more.

thx -

CJ

<!-- Code here>
....
ImageButton [] ImageArray = new ImageButton[FileName.Length];
....
for (int i = 0; i < FileName.Length; i++)
{
ImageArray= new ImageButton();
...
this.Controls.Add(ImageArray);
}
....

<HTML>
....
<FORM id="display" method="post" runat="server">
...
</FORM>
</HTML>

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

Stack Trace:


[HttpException (0x80004005): Control 'Preview1' of type 'ImageButton' must
be placed inside a form tag with runat=server.]
System.Web.UI.Page.VerifyRenderingInServerForm(Control control)
System.Web.UI.WebControls.ImageButton.AddAttributesToRender(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.RenderBeginTag(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.Render(HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
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()

<end code --->
 
E

Elton Wang

Hi CJ,

If you add ImageButton to form rather than page, the
ImageButton will be placed inside form tag:

HtmlForm form = (HtmlForm)this.FindControl("Form1");

//...
form.Controls.Add(ImageArray);
//...

Hope it's helpful to you.

Elton Wang

(e-mail address removed)
-----Original Message-----
Morning -

I am hoping somebody from this group can help me out here...

I have been trying to add an array of ImageButtons to my WebForm however I
keep getting an exception that I can't seem to find an answer for any where
on the net.

Any help in the right direction would be greatly appreciated. If more
code/source is need please let me know and I will post more.

thx -

CJ

<!-- Code here>
....
ImageButton [] ImageArray = new ImageButton [FileName.Length];
....
for (int i = 0; i < FileName.Length; i++)
{
ImageArray= new ImageButton();
...
this.Controls.Add(ImageArray);
}
....

<HTML>
....
<FORM id="display" method="post" runat="server">
...
</FORM>
</HTML>

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

Stack Trace:


[HttpException (0x80004005): Control 'Preview1' of type 'ImageButton' must
be placed inside a form tag with runat=server.]
System.Web.UI.Page.VerifyRenderingInServerForm(Control control)System.Web.UI.WebControls.ImageButton.AddAttributesToRender
(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.RenderBeginTag
(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.Render (HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
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()

<end code --->


.
 
G

Guest

Hi,

You need to give some part of the source code and the error description.
Then only we can figure out.

Prakash.C

Elton Wang said:
Hi CJ,

If you add ImageButton to form rather than page, the
ImageButton will be placed inside form tag:

HtmlForm form = (HtmlForm)this.FindControl("Form1");

//...
form.Controls.Add(ImageArray);
//...

Hope it's helpful to you.

Elton Wang

(e-mail address removed)
-----Original Message-----
Morning -

I am hoping somebody from this group can help me out here...

I have been trying to add an array of ImageButtons to my WebForm however I
keep getting an exception that I can't seem to find an answer for any where
on the net.

Any help in the right direction would be greatly appreciated. If more
code/source is need please let me know and I will post more.

thx -

CJ

<!-- Code here>
....
ImageButton [] ImageArray = new ImageButton [FileName.Length];
....
for (int i = 0; i < FileName.Length; i++)
{
ImageArray= new ImageButton();
...
this.Controls.Add(ImageArray);
}
....

<HTML>
....
<FORM id="display" method="post" runat="server">
...
</FORM>
</HTML>

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

Stack Trace:


[HttpException (0x80004005): Control 'Preview1' of type 'ImageButton' must
be placed inside a form tag with runat=server.]
System.Web.UI.Page.VerifyRenderingInServerForm(Control control)System.Web.UI.WebControls.ImageButton.AddAttributesToRender
(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.RenderBeginTag
(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.Render (HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
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()

<end code --->


.

 

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,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top