Need to intercept DropDownList.OnSelectedIndexChanged()

J

Jeff Bowman

I have an editable DataGrid that contains a few
DropDownLists in its EditRow. Each
DropDownList.AutoPostBack is set to True, and each
DropDownList.OnSelectedIndexChanged calls a server-side
method.

The form contains a hidden field called 'txtUserMode',
and I use it to store one of these three values:

0 - Adding
1 - Editing
2 - Viewing

I do this because I have code in ItemCreated that needs
to know what state the grid is currently in, so it can do
all kinds of magic stuff. To this end, I set
txtUserMode.Value in the DataGrid's EditCommand event,
and also in the UpdateCommand and CancelCommand events.

This all works fine until I select a value from one of
the DropDownLists, and the form posts back--I'm then not
able to pick up the correct UserMode from within
ItemCreated, where my crucial logic lies. You see, the
txtUserMode field is set to 2 by default, so when there's
no EditCommand event the grid always thinks it's in
Viewing mode.

I tried setting txtUserMode.Value from within one of the
DropDownList's server-side methods, but unfortunately the
field doesn't pick up the new value before ItemCreated
fires. The same is the case if I use a
RegisterStartupScript approach from within the
OnSelectedIndexChanged methods.

I'm thinking I might be able to work around this problem
if I can have DropDownList.OnSelectedIndexChanged call a
javascript on the client side to set the value of
txtUserMode BEFORE postback, and then in turn have that
javascript execute the standard .NET postback.

I've scoured the net for leads and ideas, but I'm running
into the old problem of "If you don't know you're looking
for a needle, how do you find it in the haystack?"

Is there a way to intercept the DropDownList's standard
PostBack code, and inject my own script call? If so, how
do I then have my script call the standard PostBack?

TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top