3

Asp.Net 2.0 framewrok - VB.Net application I have a UserControl containing a Asp.Net DropDownList.

Things already researched and \ or tried:

  • The control gets bound to data on page load inside if not Page.IsPostBack (only loads once)
  • ID proprety is set for control (ID = ddlMyControl)
  • AutoPostBack is set to true
  • EnableViewState on the control is set to true
  • AutoEventWireUp in the UserControl declaration is set to true
  • EnableEventValidation is set to false in the parent page

The control will not fire it's SelectedIndexChanged event no matter what I do. HELP !!

Thanks :)

Jim Evans
  • 6,285
  • 10
  • 37
  • 60

6 Answers6

4

I was running into a similar issue and it was because I left AutoPostBack="true" out of the control definition. In your original post, you said you had tried that but the posted code:

<uc3:TheControl ID="ucMyControl" runat="server" />

does not reflect the AutoPostBack property. I added that to mine and it took care of my problem. Hope that helps.

Jason
  • 68
  • 5
  • Excellent point - I had set autopostback = true on the dropdown control but not on the usercontrol that contains it. I'll give that a try. – Jim Evans Jul 21 '11 at 19:18
  • @Jason You mean by simply adding the property to the uc? Because I tried `` and it didn't work for me. I believe I have exactly the same setup as the OP too. :( – Chiramisu Jan 29 '13 at 01:26
1

I know it's very late but I thought it will help others who faced the same problem.

I'm assuming you want to fire the SelectedIndexChanged Event of a DropDownList which is already bound with some data!
For example [C#]

ddlMyDropDown.DataSource = listOfCustomers;
ddlMyDropDown.DataTextField = "CustomerName";
ddlMyDropDown.DataValueField = "CustomerID";
ddlMyDropDown.DataBind();
ddlMyDropDown.CauseValidation = false;

I'm assuming you are using asp.net (latest version).. maybe 4.0.

Hans Olsson
  • 54,199
  • 15
  • 94
  • 116
iTeach
  • 11
  • 1
0

What about the "surounding" page. You could try your UserControl within another page?

How do you add the event handler? How do you include the use control? (When via code, may be to late?)

May be you could show some code ;-)

Robert
  • 1,466
  • 10
  • 25
0

The UserControl is not being loaded dynamicaly but added to the parent page at design time in the HTML of the page

<uc3:TheControl ID="ucMyControl" runat="server" />

The event handler is codded in the code behind of the UserContorl itself - standard stuff:

 Protected Sub ddlMyThing_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlMyThing.SelectedIndexChanged
    'Do event stuff here.
End Sub
Jim Evans
  • 6,285
  • 10
  • 37
  • 60
  • 2
    It would be better to extend the original question instead to make it an communication thread - I believe.. – Robert Feb 25 '10 at 16:13
  • No - the autopostback is not firing at all - I set breakpoints in debug on both the page load and also in the SelectIndexChanged event handler and the app just flys right by without stopping when I select a new item in the DropDownList. Button clicks in the same usercontrol DO fire however - now go figure :) – Jim Evans Feb 25 '10 at 16:55
  • I'm not sure what you mean by extending the question to a communication thread - but if you tell me how.... – Jim Evans Feb 25 '10 at 16:59
  • Actually - there seems to be a javascript error on the page: this.getelement().style is null or not set After googling that a lot it seems to be related to the Asp.Net AJAX Toolkit - which is in use here. But found no resolution. – Jim Evans Feb 26 '10 at 16:44
0

Have you set the onselectedindexchanged="ddlMyThing_SelectedIndexChanged" property of the ddl?

Ahmad
  • 22,657
  • 9
  • 52
  • 84
  • No - there is a handles attribute on the event handler Protected Sub ddlMyThing_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlMyThing.SelectedIndexChanged 'Do event stuff here. End Sub – Jim Evans Feb 25 '10 at 21:46
0

I think you need to set EnableEventValidation to True.

Check this out.

http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_22405007.html

Hope this helps.

Thanks,

Raja

Raja
  • 3,608
  • 3
  • 28
  • 39
  • 1
    I will not pay that site for an answer :) - that being said - EnableEventValidation is true by default if not declared and the postback was not wroking. One of the articles I found in my research had a resolution to the exact same problem by setting it to false - did not work for me though. – Jim Evans Feb 25 '10 at 20:17