Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Handling events on automatically generated web controls

Reply
Thread Tools

Handling events on automatically generated web controls

 
 
JezB
Guest
Posts: n/a
 
      06-24-2004
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 ?


 
Reply With Quote
 
 
 
 
JezB
Guest
Posts: n/a
 
      06-24-2004
Incidentally, I have tried generating IDs for my buttons as the error
suggests but this doesnt help. Same thing happens.

"JezB" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 ?
>
>



 
Reply With Quote
 
 
 
 
Ireney Berezniak
Guest
Posts: n/a
 
      06-25-2004
JezB wrote:

> Incidentally, I have tried generating IDs for my buttons as the error
> suggests but this doesnt help. Same thing happens.
>
> "JezB" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>
>>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.
 
Reply With Quote
 
JezB
Guest
Posts: n/a
 
      06-25-2004
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" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> 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" <(E-Mail Removed)> 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" <(E-Mail Removed)> wrote in message
> > > news:(E-Mail Removed)...
> > >
> > >>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.

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automatically create stubs for handling events from aspx/ascx sourceview? DC ASP .Net 2 03-06-2008 04:09 PM
Differentiate between user caused events and script generated events jmpinchot@gmail.com Javascript 1 04-27-2007 03:05 AM
Dynamicly generated controls not firing their events ThunderMusic ASP .Net 1 08-22-2006 05:12 PM
Handling events generated by a Master Page in a content placeholde =?Utf-8?B?RmVkZXJpY28=?= ASP .Net 5 02-01-2006 03:11 PM
Events Events Events Please Help Chris ASP .Net Web Controls 0 08-30-2005 08:21 PM



Advertisments