DropDownList.SelectedIndexChanged event not firing

Discussion in 'ASP .Net Web Controls' started by BentleyInc, Dec 10, 2004.

  1. BentleyInc

    BentleyInc Guest

    I've created a Web user control that contains a DropDownList and this
    DropDownList gets created and loaded in init() everytime. I set
    AutoPostBack=true and registered the event.

    I'm using the same user control at 2 different places. When running in the
    ASP.NET web form, the DropDownList is working fine and the
    SelectedIndexChanged event handler does get called, but when running the
    same user control in my Sharepoint Web part page, the event never gets
    fired.

    Has anyone out there had similar problem (not necessarily to be Sharepoint
    related) that SelectedIndexChanged is not firing? Any possible reasons? It
    definitely does a post back just the event is not firing.

    Thanks in advance.

    Jingmei Li
    Bentley Systems Inc.
     
    BentleyInc, Dec 10, 2004
    #1
    1. Advertising

  2. Hi Jingmei,

    We have reviewed this issue and are currently researching on it. We will
    update you ASAP. Thanks for your patience!

    Kevin Yu
    =======
    "This posting is provided "AS IS" with no warranties, and confers no
    rights."
     
    Kevin Yu [MSFT], Dec 11, 2004
    #2
    1. Advertising

  3. Hi Bentley,

    Thanks for your posting. From your description, you've created a custom
    WebUserControl which contains a dynamic created DropDownList(with
    autopostback= true). However, you found the dropdownlist's
    selectedindexchanged event handler is not executed correctly when postback,
    yes?

    Based on my experience, if this is a repeatable behavior, it is likely that
    there is something wrong with the code that registring the eventhandler for
    the dropdownlist. Would you try recreating a simple version of the
    usercontrol which just contain such a dropdownlist and provide us the
    detailed code? Thus we can have a further look or do some local test to see
    whether there is something else we can find.
    Please feel free to let me know if there is any other findings or any
    further questions.
    Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Dec 13, 2004
    #3
  4. BentleyInc

    BentleyInc Guest

    I think this is definitely related to the timing of registering the
    evenhandler.

    Currently I'm registering the event handler in OnInit() like below:
    //ViewList is my DropDownList
    //AutoPostBack and EnableViewState are both set true.
    this.ViewList.SelectedIndexChanged+=new
    EventHandler(ViewList_SelectedIndexChanged);
    BUT at this time, ViewList is empty since I don't have the info to populate
    the ListItems yet.

    Since this is within a Consumer web part, I have a method
    ConsumWebPartParaters() that will be called when the Provider web part is
    passing info to this web part. In this method, I have sth like the following:
    ....
    this.ViewList.Items.Clear();
    ViewList.Items.Add(new ListItem("", ""));

    if (sizeViews > 0)
    {
    savedViews = savedViewTable.ChildNodes;
    foreach (XmlNode xmlNode in savedViews)
    {
    savedViewName = xmlNode.Attributes["name"].Value;
    ... //more code
    ViewList.Items.Add(new ListItem(text, "sview=" + savedViewName));
    }
    }


    I tried registering the even handler again after the ViewList is populated,
    but that didn't make any difference.

    Thanks,
    Jingmei Li
    Bentley Systems Inc.


    "Steven Cheng[MSFT]" wrote:

    > Hi Bentley,
    >
    > Thanks for your posting. From your description, you've created a custom
    > WebUserControl which contains a dynamic created DropDownList(with
    > autopostback= true). However, you found the dropdownlist's
    > selectedindexchanged event handler is not executed correctly when postback,
    > yes?
    >
    > Based on my experience, if this is a repeatable behavior, it is likely that
    > there is something wrong with the code that registring the eventhandler for
    > the dropdownlist. Would you try recreating a simple version of the
    > usercontrol which just contain such a dropdownlist and provide us the
    > detailed code? Thus we can have a further look or do some local test to see
    > whether there is something else we can find.
    > Please feel free to let me know if there is any other findings or any
    > further questions.
    > Thanks.
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
    >
    >
     
    BentleyInc, Dec 14, 2004
    #4
  5. Hi Jingmei,

    Thanks for your response. From your description, you do the dropdownlist
    item generation in a certain method which is called when a provider
    webpart is passed in. And your dropdownlist's selectedindexchanged event
    handled is registered in the webcontrol's OnInit event,yes?

    Is your custom wecontrol implement the INamingContainer interface? If not,
    you need to implement it first so as to make sure your custom control can
    contains other nested sub controls correctly. After that , as for a asp.net
    custom webserver control( or WSS WebPart), I think the most reasonable
    place for creating child controls and wireup event handler for them is the
    "CreateChildControls" method(overrideable). I'm not sure whether you've
    used this method to construct the whole control's control tree? If not, I
    strong recommend that you try creating the dropdownlist control and
    register the eventhandler for it in the CustomControl's CreateChildControl
    event. For example:

    =======================
    protected override void CreateChildControls()
    {
    Controls.Clear();

    DropDownList ddl = new DropDownList();
    ddl.ID = "lstItems";
    ddl.AutoPostBack = true;
    ddl.SelectedIndexChanged += new EventHandler(ddl_SelectedIndexChanged);

    ddl.Items.Add("aaa");
    ddl.Items.Add("bbb");
    ddl.Items.Clear();
    ddl.Items.Add("ccc");
    ddl.Items.Add("ddd");


    Controls.Add(ddl);
    }

    ======================

    And at runtime, the asp.net runtime will call the CreateChildControls
    method at the proper time. The first time the control is loaded( !
    IsPostBack), the method maybe called before the page's PreRender event and
    in PostBacks, it may be called in Init event.

    Please have a check and if there is anything unclear ,please feel free to
    post here. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
     
    Steven Cheng[MSFT], Dec 14, 2004
    #5
    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. DesignerX
    Replies:
    2
    Views:
    3,851
    Bob Carsto
    Nov 14, 2003
  2. Paul Lacey
    Replies:
    2
    Views:
    2,714
    =?Utf-8?B?TmlrYW5kZXIgJiBNYXJncmlldCBCcnVnZ2VtYW4=
    Feb 17, 2005
  3. Lew Barnesson
    Replies:
    3
    Views:
    814
    Lew Barnesson
    Dec 4, 2004
  4. =?Utf-8?B?Q3VybHlGcm8=?=

    dropdownlist selectedIndexChanged event not firing

    =?Utf-8?B?Q3VybHlGcm8=?=, Aug 14, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    2,634
    =?Utf-8?B?Q3VybHlGcm8=?=
    Aug 14, 2005
  5. Dabbler

    DropDownList selectedIndexChanged event not firing

    Dabbler, May 6, 2005, in forum: ASP .Net Web Controls
    Replies:
    6
    Views:
    835
    Josh Behl
    Aug 13, 2006
Loading...

Share This Page