Create ImageButton Dynamiclly

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
Using ASP .Net,

I'm trying to create a ImageButton when the user clicks on a button,

this is my code:

protected void logout_btn_Click(object sender, ImageClickEventArgs e)
{

ImageButton ib = new ImageButton();
ib.ID = "IWantToPlay";
ib.ImageUrl = "~Images/basketballPlayers.jpg";
ib.Width = 45;
this.Controls.Add(ib);
}

i get the following error:
Control 'IWantToPlay' of type 'ImageButton' must be placed inside a form tag
with runat=server.

how can i create the imageButton dynamiclly?

Thanks,
Gidi
 
Gidi said:
Hi,
Using ASP .Net,

I'm trying to create a ImageButton when the user clicks on a button,

this is my code:

protected void logout_btn_Click(object sender, ImageClickEventArgs e)
{

ImageButton ib = new ImageButton();
ib.ID = "IWantToPlay";
ib.ImageUrl = "~Images/basketballPlayers.jpg";
ib.Width = 45;
this.Controls.Add(ib);
}

i get the following error:
Control 'IWantToPlay' of type 'ImageButton' must be placed inside a form tag
with runat=server.

how can i create the imageButton dynamiclly?

Thanks,
Gidi

You are putting the control at the root level of the page, which will be
outside the html element. Put the control inside the form.
 
Gidi,

When you first put a panel on your page, then everything becomes easy. You
can then add it to the panel in the way you do now.

Cor
 
Back
Top