Need to intercept DropDownList.OnSelectedIndexChanged()

Discussion in 'ASP .Net Web Controls' started by Jeff Bowman, Dec 12, 2003.

  1. Jeff Bowman

    Jeff Bowman Guest

    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
    Jeff Bowman, Dec 12, 2003
    #1
    1. Advertising

  2. Jeff Bowman

    Jeff Bowman Guest

    I solved the problem by moving my code from ItemCreated
    to ItemDataBound.


    >-----Original Message-----
    >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
    >
    >
    >.
    >
    Jeff Bowman, Dec 13, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alexander Reichman

    Dropdownlist onselectedIndexChanged event not fires

    Alexander Reichman, Oct 17, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    23,313
  2. Paul L
    Replies:
    1
    Views:
    7,297
  3. Replies:
    8
    Views:
    761
  4. =?Utf-8?B?Z2xlbm4=?=

    DropDownList control and OnSelectedIndexChanged event

    =?Utf-8?B?Z2xlbm4=?=, Apr 21, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    8,351
    =?Utf-8?B?Y2xpY2tvbg==?=
    Apr 21, 2006
  5. =?Utf-8?B?Z2xlbm4=?=
    Replies:
    5
    Views:
    3,659
    Jeff Dillon
    Apr 25, 2006
Loading...

Share This Page