locked
OnSelectedIndexChange does not work when When the form reload to edit/update the saved data RRS feed

  • Question

  • User899592849 posted

    Hello,

    When the empty form was first loaded to enter data, the event OnSelectedIndexChange in dropdownlist (DD_Seat) works as expected. But
    When the form reload to edit/update the saved data, the event OnSelectedIndexChange does not work.  Sample code below.  Thanks

    <tr>
    <td><asp:Label ID="Label9" runat="server" Text="Seat:" CssClass="formlabel"></asp:Label></td>
    td><asp:DropDownList ID="DD_Seat" AutoPostBack="true" OnSelectedIndexChanged="DD_Seat_TextChanged" EnableViewState="true" runat="server" CssClass="forminput /></td>
    </tr>
    
    
    <tr>
    <td><asp:Label ID="Label3" runat="server" Text="Gate:" CssClass="formlabel"></asp:Label></td>
    <td><asp:DropDownList ID="DD_Gate" AutoPostBack="true" runat="server" CssClass="forminput" /></td>
    </tr>
    
    
    -----code behind----
    Protected Sub DD_Seat_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DD_Seat.TextChanged If DD_Seat.SelectedValue = 1 Then DD_Gate.SelectedValue = 23 ElseIf DD_Seat.SelectedValue = 4 Then DD_Gate.SelectedValue = 2 Else DD_Gate.SelectedValue = 8 End If End Sub

    Friday, February 8, 2019 7:27 PM

All replies

  • User475983607 posted

    The DropDownList is configured to auto postback.  Every time you make a change the dropdown the form posts.  If you are expecting the OnSelectedIndexChanged after clicking a button, well, that's impossible.  Set AutoPostBack="false" to fire the event on a button click.

    Friday, February 8, 2019 7:49 PM
  • User899592849 posted

    There are no other buttons exception the SAVE button to save data to the database (Add.aspx). The records then show in a listbox to edit/update if needed (list.aspx).
    Select a record from the listbox on (list.aspx) page then click Edit button this takes back to Add.aspx page to make any changes; this is where the OnSelectedIndexChanged stops working. There are 2 pages involved in this.  Thanks.

    Friday, February 8, 2019 9:13 PM
  • User475983607 posted

    There are no other buttons exception the SAVE button to save data to the database (Add.aspx). The records then show in a listbox to edit/update if needed (list.aspx).
    Select a record from the listbox on (list.aspx) page then click Edit button this takes back to Add.aspx page to make any changes; this is where the OnSelectedIndexChanged stops working. There are 2 pages involved in this.  Thanks.

    The code is written in such a way that the OnSelectedIndexChanged will never fire from a button click. 

    If you need help, post code that reproduces the issue.  Keep in mind the OnSelectedIndexChanged has been around for almost 20 years.

    Friday, February 8, 2019 9:20 PM
  • User899592849 posted

    Thanks for looking into this but that is the code above. I don't think other code relevant to this specific issue and only confuse more......OnSelectedIndexChanged event works perfectly fine when I insert data. But when I retrieve the data to make changes that is when it produces the issue.  Insert/update using the same Add.aspx page.  since it is update, it has data in the fields is that why it is causing the event not to fire?  Thanks.

    Friday, February 8, 2019 9:51 PM
  • User475983607 posted

    sn002

    Thanks for looking into this but that is the code above. I don't think other code relevant to this specific issue and only confuse more......OnSelectedIndexChanged event works perfectly fine when I insert data. But when I retrieve the data to make changes that is when it produces the issue.  Insert/update using the same Add.aspx page.  since it is update, it has data in the fields is that why it is causing the event not to fire?  Thanks.

    I cannot reproduce the issue with the code shown.  Every time I change the dropdown the forms posts back and executes the handler. 

    You must have bugs elsewhere in the code.  

    Friday, February 8, 2019 10:11 PM
  • User61956409 posted

    Hi sn002,

    Select a record from the listbox on (list.aspx) page then click Edit button this takes back to Add.aspx page to make any changes; this is where the OnSelectedIndexChanged stops working. There are 2 pages involved in this.

    As you said "There are 2 pages involved in this", if you can share more detailed code of these two page, we can reproduce and troubleshoot issue better.

    With Regards,

    Fei Han

    Wednesday, February 20, 2019 9:35 AM