Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > this.Controls.Add(ImageButton[i]) exception

Reply
Thread Tools

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

 
 
CJ Oakwood
Guest
Posts: n/a
 
      01-03-2005
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[i]= new ImageButton();
...
this.Controls.Add(ImageArray[i]);
}
....

<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(Con trol control)
System.Web.UI.WebControls.ImageButton.AddAttribute sToRender(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.RenderBeginTa g(HtmlTextWriter
writer)
System.Web.UI.WebControls.WebControl.Render(HtmlTe xtWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Control.RenderChildren(HtmlTextWrite r writer)
System.Web.UI.Control.Render(HtmlTextWriter writer)
System.Web.UI.Control.RenderControl(HtmlTextWriter writer)
System.Web.UI.Page.ProcessRequestMain()

<end code --->


 
Reply With Quote
 
 
 
 
Elton Wang
Guest
Posts: n/a
 
      01-03-2005
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[i]);
//...

Hope it's helpful to you.

Elton Wang

http://www.velocityreviews.com/forums/(E-Mail 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[i]= new ImageButton();
> ...
> this.Controls.Add(ImageArray[i]);
> }
>....
>
><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(Con trol

control)
>

System.Web.UI.WebControls.ImageButton.AddAttribute sToRender
(HtmlTextWriter
>writer)
> System.Web.UI.WebControls.WebControl.RenderBeginTa g

(HtmlTextWriter
>writer)
> System.Web.UI.WebControls.WebControl.Render

(HtmlTextWriter writer)
> System.Web.UI.Control.RenderControl(HtmlTextWriter

writer)
> System.Web.UI.Control.RenderChildren(HtmlTextWrite r

writer)
> System.Web.UI.Control.Render(HtmlTextWriter writer)
> System.Web.UI.Control.RenderControl(HtmlTextWriter

writer)
> System.Web.UI.Page.ProcessRequestMain()
>
><end code --->
>
>
>.
>

 
Reply With Quote
 
 
 
 
=?Utf-8?B?UHJha2FzaC5ORVQ=?=
Guest
Posts: n/a
 
      01-04-2005
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" wrote:

> 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[i]);
> //...
>
> Hope it's helpful to you.
>
> Elton Wang
>
> (E-Mail 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[i]= new ImageButton();
> > ...
> > this.Controls.Add(ImageArray[i]);
> > }
> >....
> >
> ><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(Con trol

> control)
> >

> System.Web.UI.WebControls.ImageButton.AddAttribute sToRender
> (HtmlTextWriter
> >writer)
> > System.Web.UI.WebControls.WebControl.RenderBeginTa g

> (HtmlTextWriter
> >writer)
> > System.Web.UI.WebControls.WebControl.Render

> (HtmlTextWriter writer)
> > System.Web.UI.Control.RenderControl(HtmlTextWriter

> writer)
> > System.Web.UI.Control.RenderChildren(HtmlTextWrite r

> writer)
> > System.Web.UI.Control.Render(HtmlTextWriter writer)
> > System.Web.UI.Control.RenderControl(HtmlTextWriter

> writer)
> > System.Web.UI.Page.ProcessRequestMain()
> >
> ><end code --->
> >
> >
> >.
> >

>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Exception of type 'System.Web.HttpUnhandledException' wasthrown.Exception has been thrown by the target of an invocation.System.WebSystem.Exception jobs ASP .Net 1 11-16-2007 05:57 PM
while executing my client program i get the exception javax.naming.LinkException: [Root exception is javax.naming.LinkException: [Root exception is javax.naming.NameNotFoundException: remaining if plz anybody know how to solve this problem then mahesh Java 0 03-08-2007 12:26 PM
Throw Exception Vs Throw New Exception Kerri ASP .Net 2 10-27-2003 02:13 PM
Re: bizaar exception that isn't really an exception jeff ASP .Net 3 06-26-2003 01:02 PM
Re: bizaar exception that isn't really an exception jeff ASP .Net 0 06-24-2003 12:46 PM



Advertisments