By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

Handling events on automatically generated web controls

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
Incidentally, I have tried generating IDs for my buttons as the error
suggests but this doesnt help. Same thing happens.

"JezB" <je***********@blueyonder.co.uk> wrote in message
news:Of**************@tk2msftngp13.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

P: n/a
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.uk> wrote in message
news:Of**************@tk2msftngp13.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

P: n/a
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 ImageClickEventHandler(b1_Click);
tb1.Controls.Add(b1);
rw.Cells.Add(tb1);

// add some other columns
...

// add the row to the table
t.Rows.Add(rw);
}
// add the table to the placeholder
PlaceHolder1.Controls.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@clgrps12...
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.uk> wrote in message
news:Of**************@tk2msftngp13.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

P: n/a
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.uk> wrote in message
news:%2***************@tk2msftngp13.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 ImageClickEventHandler(b1_Click);
tb1.Controls.Add(b1);
rw.Cells.Add(tb1);

// add some other columns
...

// add the row to the table
t.Rows.Add(rw);
}
// add the table to the placeholder
PlaceHolder1.Controls.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@clgrps12...
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.uk> wrote in message
news:Of**************@tk2msftngp13.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 discussion thread is closed

Replies have been disabled for this discussion.