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

Discussion in 'ASP .Net' started by CJ Oakwood, Jan 3, 2005.

  1. CJ Oakwood

    CJ Oakwood Guest

    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 --->
     
    CJ Oakwood, Jan 3, 2005
    #1
    1. Advertising

  2. CJ Oakwood

    Elton Wang Guest

    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



    >-----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 --->
    >
    >
    >.
    >
     
    Elton Wang, Jan 3, 2005
    #2
    1. Advertising

  3. 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);
    > //...
    >
    > Hope it's helpful to you.
    >
    > Elton Wang
    >
    >
    >
    > >-----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 --->
    > >
    > >
    > >.
    > >

    >
     
    =?Utf-8?B?UHJha2FzaC5ORVQ=?=, Jan 4, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason
    Replies:
    1
    Views:
    406
    One Handed Man \( OHM#\)
    Jun 11, 2004
  2. Jason

    Image & ImageButton controls

    Jason, Jun 13, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    382
    Jason
    Jun 13, 2004
  3. Jason

    Image & ImageButton controls

    Jason, Jun 13, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    308
    Jason
    Jun 13, 2004
  4. Chad Scharf
    Replies:
    3
    Views:
    922
    Chad Scharf
    Oct 18, 2007
  5. MarkMurphy

    Inherit from ImageButton, add text property

    MarkMurphy, Jul 6, 2004, in forum: ASP .Net Web Controls
    Replies:
    5
    Views:
    385
    MarkMurphy
    Jul 14, 2004
Loading...

Share This Page