473,837 Members | 1,695 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handling events on automatically generated web controls

I am dynamically creating WebControls and creating them on my page. Some of
these are buttons, and I attach events to these buttons. The problem is
these force a post-back, so I must regenerate all the webcontrols in the
same way (I am assuming - am I right?).

It was all working fine but now I get the error:

"An error has occurred because a control with auto-generated id '_ctl129'
could not be located to raise a postback event. To avoid this error,
explicitly set the ID property of controls that raise postback events."

occurring between Page_Load and actually firing the event. I can basically
understand why but I dont know why it was working and now it isnt (I just
added some code to evaluate a dataset in generating the webcontrols - if I
take this out it works again).

What can I do about it ?
Nov 18 '05 #1
4 1593
Incidentally, I have tried generating IDs for my buttons as the error
suggests but this doesnt help. Same thing happens.

"JezB" <je***********@ blueyonder.co.u k> wrote in message
news:Of******** ******@tk2msftn gp13.phx.gbl...
I am dynamically creating WebControls and creating them on my page. Some of these are buttons, and I attach events to these buttons. The problem is
these force a post-back, so I must regenerate all the webcontrols in the
same way (I am assuming - am I right?).

It was all working fine but now I get the error:

"An error has occurred because a control with auto-generated id '_ctl129'
could not be located to raise a postback event. To avoid this error,
explicitly set the ID property of controls that raise postback events."

occurring between Page_Load and actually firing the event. I can basically
understand why but I dont know why it was working and now it isnt (I just
added some code to evaluate a dataset in generating the webcontrols - if I
take this out it works again).

What can I do about it ?

Nov 18 '05 #2
JezB wrote:
Incidentally, I have tried generating IDs for my buttons as the error
suggests but this doesnt help. Same thing happens.

"JezB" <je***********@ blueyonder.co.u k> wrote in message
news:Of******** ******@tk2msftn gp13.phx.gbl...
I am dynamically creating WebControls and creating them on my page. Some


of
these are buttons, and I attach events to these buttons. The problem is
these force a post-back, so I must regenerate all the webcontrols in the
same way (I am assuming - am I right?).

It was all working fine but now I get the error:

"An error has occurred because a control with auto-generated id '_ctl129'
could not be located to raise a postback event. To avoid this error,
explicitly set the ID property of controls that raise postback events."

occurring between Page_Load and actually firing the event. I can basically
understand why but I dont know why it was working and now it isnt (I just
added some code to evaluate a dataset in generating the webcontrols - if I
take this out it works again).

What can I do about it ?


What dynamic method are you using to create those web controls? Adding
them to a repeater maybe? Loading from a path? When you say
WebControls, I'm assuming you mean the intrinsic controls, such as
asp:textbox or are you maybe talking about Customr Web Controls you
created, or Custome User Controls? Too many pieces missing to give you
a definite answer ... a code sample would help.

ib.
Nov 18 '05 #3
I create an HtmlTable object then in a loop populate the rows and columns -
some of the columns contain ImageButton controls, to which I attach the
events. Then I add the HtmlTable to a placeholder that I have embedded into
the design surface. ie (pseudo-code) :-

HtmlTable t = new HtmlTable();
foreach (...)
{
HtmlTableRow rw = new HtmlTableRow();

// add a button column
HtmlTableCell tb1 = new HtmlTableCell() ;
ImageButton b1 = new ImageButton();
b1.Click += new ImageClickEvent Handler(b1_Clic k);
tb1.Controls.Ad d(b1);
rw.Cells.Add(tb 1);

// add some other columns
...

// add the row to the table
t.Rows.Add(rw);
}
// add the table to the placeholder
PlaceHolder1.Co ntrols.Add(t);

Clicking on the generated imagebutton forces a postback before the event is
called (is there any way to prevent this?) so the same loop is executed
before the event fires. Problem being that the event does NOT then fire, I
get the error.

"Ireney Berezniak" <ir************ **@gmail.com> wrote in message
news:8HMCc.4241 $l6.763@clgrps1 2...
JezB wrote:
Incidentally, I have tried generating IDs for my buttons as the error
suggests but this doesnt help. Same thing happens.

"JezB" <je***********@ blueyonder.co.u k> wrote in message
news:Of******** ******@tk2msftn gp13.phx.gbl...
I am dynamically creating WebControls and creating them on my page. Some


of
these are buttons, and I attach events to these buttons. The problem is
these force a post-back, so I must regenerate all the webcontrols in the
same way (I am assuming - am I right?).

It was all working fine but now I get the error:

"An error has occurred because a control with auto-generated id '_ctl129'could not be located to raise a postback event. To avoid this error,
explicitly set the ID property of controls that raise postback events."

occurring between Page_Load and actually firing the event. I can basicallyunderstand why but I dont know why it was working and now it isnt (I justadded some code to evaluate a dataset in generating the webcontrols - if Itake this out it works again).

What can I do about it ?


What dynamic method are you using to create those web controls? Adding
them to a repeater maybe? Loading from a path? When you say
WebControls, I'm assuming you mean the intrinsic controls, such as
asp:textbox or are you maybe talking about Customr Web Controls you
created, or Custome User Controls? Too many pieces missing to give you
a definite answer ... a code sample would help.

ib.

Nov 18 '05 #4
I got round it by saving my HtmlTable object in session, then on postpack
reinstating it and adding it again to the placeholder (rather than going
through the loop again).

"JezB" <je***********@ blueyonder.co.u k> wrote in message
news:%2******** *******@tk2msft ngp13.phx.gbl.. .
I create an HtmlTable object then in a loop populate the rows and columns - some of the columns contain ImageButton controls, to which I attach the
events. Then I add the HtmlTable to a placeholder that I have embedded into the design surface. ie (pseudo-code) :-

HtmlTable t = new HtmlTable();
foreach (...)
{
HtmlTableRow rw = new HtmlTableRow();

// add a button column
HtmlTableCell tb1 = new HtmlTableCell() ;
ImageButton b1 = new ImageButton();
b1.Click += new ImageClickEvent Handler(b1_Clic k);
tb1.Controls.Ad d(b1);
rw.Cells.Add(tb 1);

// add some other columns
...

// add the row to the table
t.Rows.Add(rw);
}
// add the table to the placeholder
PlaceHolder1.Co ntrols.Add(t);

Clicking on the generated imagebutton forces a postback before the event is called (is there any way to prevent this?) so the same loop is executed
before the event fires. Problem being that the event does NOT then fire, I
get the error.

"Ireney Berezniak" <ir************ **@gmail.com> wrote in message
news:8HMCc.4241 $l6.763@clgrps1 2...
JezB wrote:
Incidentally, I have tried generating IDs for my buttons as the error
suggests but this doesnt help. Same thing happens.

"JezB" <je***********@ blueyonder.co.u k> wrote in message
news:Of******** ******@tk2msftn gp13.phx.gbl...

>I am dynamically creating WebControls and creating them on my page. Some
of

>these are buttons, and I attach events to these buttons. The problem is>these force a post-back, so I must regenerate all the webcontrols in the>same way (I am assuming - am I right?).
>
>It was all working fine but now I get the error:
>
>"An error has occurred because a control with auto-generated id '_ctl129'>could not be located to raise a postback event. To avoid this error,
>explicitly set the ID property of controls that raise postback events.">
>occurring between Page_Load and actually firing the event. I can basically>understand why but I dont know why it was working and now it isnt (I just>added some code to evaluate a dataset in generating the webcontrols -
if
I>take this out it works again).
>
>What can I do about it ?
>
>

What dynamic method are you using to create those web controls? Adding
them to a repeater maybe? Loading from a path? When you say
WebControls, I'm assuming you mean the intrinsic controls, such as
asp:textbox or are you maybe talking about Customr Web Controls you
created, or Custome User Controls? Too many pieces missing to give you
a definite answer ... a code sample would help.

ib.


Nov 18 '05 #5

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

Similar topics

2
2111
by: Eric Newton | last post by:
VB's more declarative nature of handling events is golden. I'm hoping C# will acquire this type of deal, in addition to the anonymous delegates. could do same as vb (actually would be easier to parse then vb due to braces) whereas you look for Handles keyword after method sig, but before opening brace of the method. compiler would implicitly build event handling code for all typed constructions, ie, any variables instances constructed...
2
1811
by: luca | last post by:
I'm trying to build a Server Control, it's a calendar to manage sellers appointments (don't answer me to use and custumize Calendar Control because unluckily it's not possible for this specific project). A piece of my control's interface is composed of a table and in each of its cells are stored informations about a seller, a date and a time range. Each of these cells has to be an interactive element: I should be able to process datas...
0
1642
by: luca | last post by:
Hi all. My problem is that I can't handle events raised from child components within a composite server control when the control is created dynamically. Everything works fine if the same control is defined within an aspx page <MyTag:MyControl id="MyControl1" runat="server">: MyControl handle succesfully events raised from its children. When I try to create dynamically MyControl and to Add it to another control, event handling doesn't work...
3
2309
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace WebApplication1 { using System;
2
4371
by: RAJ | last post by:
In our multi-tier application, we have several ASP.NET user controls which will update the same data source provided by middle tier logic. In this particular scenario we have one user control displaying the contents of the data source, whilst another control updates the datasource via a command buttons implementation of 'Click', an event raised in the 'Handle Postback Events' stage of the control execution life cycle (via the...
12
2827
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown when menu items are clicked.Besides these i would like to put a custom status bar. Any error message encountered in any of the webpage will be displayed in the banner. The problem iam encountering is how to access the customer status bar in child...
1
1045
by: krishna | last post by:
Hi, Hi, I would like to handle the events for the dynamically created controls at runtime. I Have written the code in HTML View of an asp.net page.like this
1
3514
by: Apu Nahasapeemapetilon | last post by:
Hello and thank you in advance for your help. Can anyone think of a reason why this code would work properly on one PC, but not another? I've got a System.Windows.Forms.UserControl that products events which I want to consume (sink) within Internet Explorer. I'm following the instructions at: ms-http://support.microsoft.com/default.aspx?kbid=313891.
2
1022
by: fix | last post by:
Hi all, I am just wondering if there is a way to generate Page_xxx events automatically instead of typing it in the code-behind file manually. For the controls on a webform, I can select them, then click the event button in the property window, then all the events are for me to select and will be generated automatically. But I can't select a page in the designer (nor a user control if I am doing a user control). Thanks!
0
9696
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10902
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10583
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10642
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9420
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5680
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5863
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4062
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3128
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.