473,387 Members | 1,520 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

dynamic button - does not go to handler

Hi

here is what I am doing - building a table dynamically

HtmlTableRow objRow = new HtmlTableRow();

tblStuff.Rows.Add(objRow);

HtmlTableCell objCellMain1 = new HtmlTableCell();

ImageButton btn1 = new ImageButton();

objCellMain1.Controls.Add(btn1);

btn1.Click += new
System.Web.UI.ImageClickEventHandler(this.changeBt n_Click);

btn1.AlternateText = "333";

objRow.Cells.Add(objCellMain1);

and of course I have that method defined

private void changeBtn_Click(object sender,
System.Web.UI.ImageClickEventArgs e)

{

// get id

ImageButton btn = (ImageButton)sender;

String vid = btn.AlternateText;

etc etc.

IT shows on the screen fine

But when I click on the button it does not go into changeBtn_Click

!!!!! HELP

Thanks

GSL
Nov 17 '05 #1
2 1369
greg wrote:
Hi

here is what I am doing - building a table dynamically

HtmlTableRow objRow = new HtmlTableRow();

tblStuff.Rows.Add(objRow);

HtmlTableCell objCellMain1 = new HtmlTableCell();

ImageButton btn1 = new ImageButton();

objCellMain1.Controls.Add(btn1);

btn1.Click += new
System.Web.UI.ImageClickEventHandler(this.changeB tn_Click);

btn1.AlternateText = "333";

objRow.Cells.Add(objCellMain1);

and of course I have that method defined

private void changeBtn_Click(object sender,
System.Web.UI.ImageClickEventArgs e)

{

// get id

ImageButton btn = (ImageButton)sender;

String vid = btn.AlternateText;

etc etc.

IT shows on the screen fine

But when I click on the button it does not go into changeBtn_Click

!!!!! HELP

Thanks

GSL

Greg,

I suspect you are generating the controls in something like:
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack)
{
// Create controls
CreateControls();
}
}

Dynamic controls need to be recreated *every* time the page is created
to allow ASP.NET to restore view state, postback data and event wireup
to the dynamically created controls. So remember to recreate them on the
postback as well.

HTH
Kev
Nov 17 '05 #2
Because your ImageButton is created dynamically,

ImageButton btn1 = new ImageButton();

you need to recreate the button on a postback in order for the button event to fire.

Tommy,

"greg" <gr***@insauctionNOSPAM.com> wrote in message news:<u3**************@TK2MSFTNGP12.phx.gbl>...
Hi

here is what I am doing - building a table dynamically

HtmlTableRow objRow = new HtmlTableRow();

tblStuff.Rows.Add(objRow);

HtmlTableCell objCellMain1 = new HtmlTableCell();

ImageButton btn1 = new ImageButton();

objCellMain1.Controls.Add(btn1);

btn1.Click += new
System.Web.UI.ImageClickEventHandler(this.changeBt n_Click);

btn1.AlternateText = "333";

objRow.Cells.Add(objCellMain1);

and of course I have that method defined

private void changeBtn_Click(object sender,
System.Web.UI.ImageClickEventArgs e)

{

// get id

ImageButton btn = (ImageButton)sender;

String vid = btn.AlternateText;

etc etc.

IT shows on the screen fine

But when I click on the button it does not go into changeBtn_Click

!!!!! HELP

Thanks

GSL

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Ashish Shridharan | last post by:
Hi All I have been trying to add a control to the header cell of a datagrid on my ASP.NET page. These controls are defined in the HTML as ASP.NET web controls. They are being added into the...
1
by: Jonathan Yong | last post by:
I observe a very weird behavior when dynamically create web control and bind events to it. Create a C# ASP.NET application, Put a PlaceHolder and Textbox onto the Web form, and try with the 4...
9
by: wASP | last post by:
Hello again to all of you geniuses, I'm having a problem trying to load dynamic controls at the initialization phase. I've read the docs, and I thought I had it figured out:...
1
by: Todd Acheson | last post by:
Attention all Guru's, Let's say I create a control at runtime similar to this: 'this is one button within a loop that creates many buttons Dim ctl as New System.Web.UI.WebControls.Button...
1
by: hybrid | last post by:
I have problems in understanding the behavior of the events triggered by dynamically created controls over a webform. Could you help me? In a webform, I have a static PlaceHolder PH containing...
1
by: andrei | last post by:
Hi Group, I have an aspx form with a variable number of buttons added dynamically, with id's like b01, b02, b03... Whenever I click one of these buttons, the form is posted back. I need to...
5
by: RA | last post by:
I have created a button dynamically; which has been added to a TableCell of a TableRow of a Table control. Is there a way to add onclick event which calls a procedure on the Server-side itself....
3
by: Kris Palmer | last post by:
hi, can somebody explain this problem? it's driving me crazy! i have a requirement to dynamically create a variable quantity of timers with associated start button based on the contents of a...
1
by: Diffident | last post by:
Hello All, I am trying to add dynamic controls onto my page and here is how I am doing that. I have a page which has a button called as "AddMoreControls" and in this button's event handler I...
5
by: Anil Gupte | last post by:
How does one access dynamic controls by name (or whatever other means)? I have the following: Dim newbtnPick As New Button newbtnPick.Name = "SliceButton" & CurSliceNum newbtnPick.Location =...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.