Last post Aug 28, 2008 04:47 PM by boolean.commando
Aug 01, 2006 04:34 AM|foxdy|LINK
Problem type: Event is not firing
Panel on Asp.net page
=> dynamically the content gets changed.
Trying to add programmatically to the panel a GridView with AutoGenerateSelectButton and its associated events. (selectedindexchanged ..) . all good but the event is not being raised “I guess”.
am I missing anything?
Here is what I do:
First, initialize the GridView
myGrid.SelectedIndex = 0;
IDE is already warning that the code (the method) below is not reachable.
sender, EventArgs e)
new Exception("The method or operation is not implemented.");
Sep 11, 2006 08:48 AM|LiquidSpy|LINK
Sep 11, 2006 10:09 AM|foxdy|LINK
Sep 15, 2007 09:03 PM|AppDevForMe|LINK
Make sure in your .aspx code that you have AutoPostBack set to true. Here is an example for a drop down listbox.
Sep 15, 2007 11:02 PM|jshepler|LINK
When dynamically adding controls that subscribe to events, the subscriptions are not "remembered" on postback - they are not saved as part of the viewstate. Therefore, you need to re-subscribe to the events when you re-create the controls (you also need
to re-create dynamically added controls for the same reason). You need to do this on or before the Page_Load event. In fact, asp.net 2.0 added the Page_PreLoad() event for such things.
Also, in case you hadn't noticed, the warning that the code is not reachable applies to the code after throwing the exception. Throwing exceptions ends the processing of the method so the code after it is, in effect, "not reachable". That exception is part
of the stub that VS builds - it needs to be removed when adding code to the method.
Jul 19, 2008 11:37 PM|erikphilips|LINK
protected void myRentalGrid_SelectedIndexChanged(object sender,
Should fix the problem for future users.
Aug 28, 2008 04:47 PM|boolean.commando|LINK
Has it already been pointed out that foxdy registered the handler "myGrid_SelectedIndexChanged" and then created "myRentalGrid_SelectedIndexChanged"?
If you aren't registering the correct event handler, of course it's not firing.