Pranav Kumar
Pranav Kumar

Reputation: 259

DropDownList SelectedIndexChanged doesn't execute when original value is reset using JQUERY

Initialization of the control is as:

<asp:DropDownList ID="ddlStudent" runat="server" OnSelectedIndexChanged="ddlStudent_SelectedIndexChanged" AutoPostBack="true" CssClass="form-control" data-toggle="tooltip" ToolTip="Select student" />

Here is the VB code for SelectedIndexChanged event(in VB):

Public Sub ddlStudent_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlStudent.SelectedIndexChanged
        Dim dsStudentInfo as DataSet = New DataSet()
        If (ddlStudent.SelectedIndex > 0) Then
               dsStudentInfo = GetStudentInfo(Convert.ToInt32(ddlStudent.SelectedItem.Value))
        End If
End Sub

When we reset the drop-down index using JQuery, it resets the dropdown index. And again when we select the previous index, it doesn't trigger server side SelectedIndexChanged event.

Here is the JQuery code to reset the dropdown:

$("[id*=ddlStudent]").prop('selectedIndex', 0);

Here is the demonstration:

NOTE: I have already tried with the following but it didn't work: 1. set dropdown "AutoPostBack" property to true 2. __doPostBack("<%=ddlStudent.ClientID %>", '');

Kindly help in finding the solution.

Upvotes: 1

Views: 292

Answers (2)

Sunil
Sunil

Reputation: 138

set dropdown "AutoPostBack" property to true

Upvotes: 0

Joel
Joel

Reputation: 100

A similar question has been asked here. Without seeing the HTML code, I'm curious if you've set the 'OnSelectedIndexChanged' attribute in the HTML? Alongside this, have you set the 'AutoPostBack' to true? This is the solution for the related question.

Upvotes: 1

Related Questions