admin管理员组

文章数量:1395730

I have an asp:Updatepanel that contains a dropdown and I run some Javascript on the onchange event of the dropdown. I also fire some server side code on the selectedindexchanged of the dropdown.

This works OK in IE, but in Firefox the selectedindexchanged event never gets called.

I think this may be something todo with onchange and selectedindexchanged conflicting but, I can't find a solution to solve this.

I have an asp:Updatepanel that contains a dropdown and I run some Javascript on the onchange event of the dropdown. I also fire some server side code on the selectedindexchanged of the dropdown.

This works OK in IE, but in Firefox the selectedindexchanged event never gets called.

I think this may be something todo with onchange and selectedindexchanged conflicting but, I can't find a solution to solve this.

Share Improve this question edited Dec 3, 2009 at 16:48 p.campbell 101k70 gold badges262 silver badges326 bronze badges asked Dec 3, 2009 at 16:35 Robert JohnstonRobert Johnston 411 silver badge2 bronze badges 4
  • 9 Don't forget to put up some code, it makes it a lot easier to get help. – ProgrammingPope Commented Dec 3, 2009 at 16:37
  • I have the same issue... anyone? – Jack Marchetti Commented Jul 21, 2010 at 15:16
  • 1 What javascript are you using? I am unable to duplicate the issue with simple javascript, so please post the code that you are using so that we can try and help. – sgriffinusa Commented Jul 21, 2010 at 17:55
  • I had this problem once before, can you post your web.config? – Nealv Commented Jul 28, 2010 at 15:16
Add a ment  | 

5 Answers 5

Reset to default 4 +25

I would agree with some of the other posters here. IE, Chrome, and FF seem to handle server-side controls with both client-side and server-side events handlers differently. It has been my experience that sometimes they wait for the client JavaScript to end, then perform the post-back to handle the server-side...but this isn't always the case.

The solution I always turn to:

Go ahead and set the onChange() event on your DropDownList only...then in your JavaScript, manually force the postback using something like the

__doPostBack('<%= DropDownList.ClientID %>', '');

syntax to make your page use that control for the postback. In your server-side code you can just query the current index value off the DropDownList, and perform whatever processing you want...the UpdatePanel should handle this situation perfectly...

I'm pretty sure that you have some problems in client side since There has been similar reports. Use firebug to track the js error. have a look at http://www.webmasterworld./profilev4.cgi?action=view&member=Nazgoth about ochange event in firefox. If you can't find the source of your problem, post your js here.

Feel free to correct me as this was my solution a very very long time ago:

We hit this and the only way we ended up being able to do it was to attach an event to the id of the dropdown itself and access it via document.getElementById (easy enough to find the id with a view source :)

Lame answer with a lame solution but that's how we got around the issue a few years back. Would be interested if anyone actually knows how to fix it :)

I had this problem once before, I solved it by changing my web.config

(check here)

Something that I have noticed is that the SelectedIndexChanged event will not fire unless the value has been changed. So if your DropDownList's ListItems do not have unique values, just add a random number to make it unique.

    Dim dt As DataTable
    Dim dr As DataRow

    Using d As DropDownList = ddl
        With d
            .Items.Clear()

            dt = GetDataTable(Params)

            ' We add the index to the value field because the values need to be unique
            ' in order for the SelectedIndexChanged event to fire correctly
            For k As Integer = 0 To dt.Rows.Count - 1
                dr = dt.Rows(k)
                .Items.Add(New ListItem(dr("column1"), k & ":" & dr("column2")))
            Next
        End With
    End Using

本文标签: javascriptASPNET DropDown SelectedIndexChanged not firing in Firefox with UpdatePanelStack Overflow