DropDownList.SelectedIndexChanged event not firing

B

BentleyInc

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.
 
K

Kevin Yu [MSFT]

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."
 
S

Steven Cheng[MSFT]

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.)
 
B

BentleyInc

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.
 
S

Steven Cheng[MSFT]

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.)
 

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

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top