473,410 Members | 1,916 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,410 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 1370
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: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.