How we can create image button control dynamically ?
-
How we can create image button control dynamically ?
-
How we can create image button control dynamically ?
ImageButton button = new ImageButton();
button.Id = "something";add this button to a panel or place holder.
-
How we can create image button control dynamically ?
Masood Kochi,SSF wrote:
How we can create image button control dynamically ?
Create object of ImageButton,Set require properties and add in the page for example ImageButton imgBtn=new ImageButton(); imgBtn.ID="imgBtn"; imgBtn.ImageUrl="imagePath"; //Add image button in page.Suppose You have put one panel control on the page and ID is pnl pnl.Controls.Add(imgBtn);
please don't forget to vote on the post that helped you.
-
How we can create image button control dynamically ?
This is trivial, the hard part is capturing viewstate from this control ( won't happen if you create it in page load, or later )
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.
-
Masood Kochi,SSF wrote:
How we can create image button control dynamically ?
Create object of ImageButton,Set require properties and add in the page for example ImageButton imgBtn=new ImageButton(); imgBtn.ID="imgBtn"; imgBtn.ImageUrl="imagePath"; //Add image button in page.Suppose You have put one panel control on the page and ID is pnl pnl.Controls.Add(imgBtn);
please don't forget to vote on the post that helped you.
Ok ..Thanks but How wecan raise click event on that image button
-
Ok ..Thanks but How wecan raise click event on that image button
Masood Kochi,SSF wrote:
but How wecan raise click event on that image button
Write this line to create Event
imgBtn.Click += new ImageClickEventHandler(imgBtn_Click);
This is event of Image Button
public void imgBtn_Click(object sender, ImageClickEventArgs e)
{
//Write your code here
}please don't forget to vote on the post that helped you.
-
Masood Kochi,SSF wrote:
but How wecan raise click event on that image button
Write this line to create Event
imgBtn.Click += new ImageClickEventHandler(imgBtn_Click);
This is event of Image Button
public void imgBtn_Click(object sender, ImageClickEventArgs e)
{
//Write your code here
}please don't forget to vote on the post that helped you.
May not work - unless the button is created early enough, it won't exist when the viewstate tree is restored.
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.
-
May not work - unless the button is created early enough, it won't exist when the viewstate tree is restored.
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.
Christian Graus wrote:
May not work
It'll work on page load event also.I worked on it many times
please don't forget to vote on the post that helped you.
-
Christian Graus wrote:
May not work
It'll work on page load event also.I worked on it many times
please don't forget to vote on the post that helped you.
Really ? Are you using .NET 3.5 ? I am using 2.0 and have found problems with this, I've also done it many times, but I had to create my controls in the loadviewstate event.
Christian Graus No longer a Microsoft MVP, but still happy to answer your questions.