Problem with _selectedIndexChanged

Last post 08-29-2008 1:37 PM by parandal1. 3 replies.

Sort Posts:

  • Problem with _selectedIndexChanged

    08-27-2008, 2:18 PM
    • Member
      15 point Member
    • parandal1
    • Member since 06-26-2008, 10:03 AM
    • Posts 80

    My code-behind function is below.

    1    Protected Sub tx_taserDeputy_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles tx_taserDeputy.SelectedIndexChanged
    2            Session("taserDeputy") = tx_taserDeputy.SelectedItem.Value
    3    
    4        End Sub
     
    
      Here is my dropdownlist
    1    <asp:DropDownList ID="tx_taserDeputy" runat="server" DataSourceID="DSesocad"
    2                                          DataTextField="NAME" DataValueField="NAME" Font-Names="Verdana" Font-Size="8pt" AppendDataBoundItems="True">
    3                                          <asp:ListItem Selected="True"></asp:ListItem>
    4                                      </asp:DropDownList>
    
      
    Obviously I have a dropdownlist that is supposed to fire the above selectedindexchanged function.  I have a popup window that is another aspx 
    page that checks to see if the session variable in the selectedindexchanged function is set properly.
    This is not working.  Any ideas what my be wrong?
     
    Paul
  • Re: Problem with _selectedIndexChanged

    08-27-2008, 2:31 PM
    • Contributor
      3,036 point Contributor
    • paindaasp
    • Member since 12-19-2007, 12:47 PM
    • Exit 3
    • Posts 522

    No PostBack?

    AutoPostBack="True"

  • Re: Problem with _selectedIndexChanged

    08-27-2008, 4:21 PM
    Answer
    • Member
      370 point Member
    • WisamAL
    • Member since 08-21-2008, 4:19 PM
    • Jerusalem
    • Posts 57

    You have to add
    AutoPostBack="True"

    And you can put the dropdownlist in a UpdatePanel of ajax so you don't feel that the page
    postback every time you choose another item at the dropdownlist

    note:UpdatePanel need a ScriptManger.

    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as
    Answer” if a marked post does not actually answer your question.
  • Re: Problem with _selectedIndexChanged

    08-29-2008, 1:37 PM
    • Member
      15 point Member
    • parandal1
    • Member since 06-26-2008, 10:03 AM
    • Posts 80

    I have added the updatepanel to the page and have nested the dropdownlist within it.  I turned autopostback = true.

    I have this in page load:

    dropdownlist1.Attributes.Add("OnSelectedIndexChanged", "javascript:test();")

    the js function test will run when the selectedindex of the drop down is changed.  I understand that with the updatepanel I don't have to worry about the whole page posting back but for some reason my test function is not firing.  The test funtion is this:

    function test() {

     

    alert(
    'hello');

    }

     

    what am I doing wrong here.  I simply want to fire JS when a user changes the selection in the dropdownlist.

     

    thanks

     

     

    Paul
Page 1 of 1 (4 items)