views:

281

answers:

1

Greetings, hopefully there is a simple solution for this complex problem. Please correct any misconceptions I have along the way. A while ago I wrote a GrivView with dynamic column capability. The columns are added in the OnInit page event so that they are added BEFORE the viewstate is applied. They are reapplied on every posting in this section of the page so that when the viewstate is applied changes that the user has made and not committed to the database are maintained. It also is required if you don’t want your viewstate control tree to get out of synch and blow everything up.

My current problem is that I am now tasked with doing essentially the same thing where the columns will be different based on a Drop Down List (I will recreate the GridView if the ddl changes, and the users will lose all work with a warning). How can I get the ID that is selected in the Drop Down List in the OnInit Event? My understanding is that when the user changes the value of the ddl on the client side a JavaScript “__doPostBack” call is fired. The page request is then sent to the server but by the time the new value is present in the event handler I am past the point where I need to add the columns.

I saw something I thought was promising when people were trying to determine what control caused a post back but that code relies on page.Request.Params.Get("__EVENTTARGET"); and page.Request.Form which are empty.

Should I look at the session state, try to ‘send’ the ID using client side manipulation, or some other method (Perhaps a sneaky way to look in the viewstate I am missing)?

Thanks for any ideas!!!

+2  A: 

A control's submitted value is available from the Request[] collection even if it appears that your form has not been reconstructed yet.

You should simply be able to get the selected value during Init() using the following:

string value = Request["myDropDownID"];
womp
For some reason, this only works on the first postback. Still better answer than mine +1
Jose Basilio