Search code examples
asp.netajaxvb.netlistviewselectedindexchanged

SelectedIndexChange Not Firing


I'm having issue with a dropdownlist updating a textbox, both held within a listview, within an update panel which in turn is in an item template.

Updated

I have got this working with the same code without the above containers in a different web page on the same project, however having trouble linking it with the lisview and other containers.

I am unsure of where the problem lies, the onClick isn't firing unless there's a call back to the server, regardless whether the drop down is contained within the containers mentioned above.

Any help would be greatly appreciated, thanks in advance.

Using asp (1st) and VB code behind (2nd).

<InsertItemTemplate>
<asp:panel runat="server" ChildrenAsTriggers="true" UpdateMode="Always">
<asp:ListView ID="ListView1" runat="server" InsertItemPosition="FirstItem" IAllowPaging="True" EnableViewState="true">
<tr>
<td>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Details")%>' TextMode="MultiLine" />
</td>
<td>
<asp:DropDownList ID="DLL" runat="server" OnSelectedIndexChanged="DLL_SelectedIndexChanged" AutoPostBack="true "EnableViewState="true">
    <asp:ListItem>Select</asp:ListItem>
    <asp:ListItem Value="1">Yes</asp:ListItem>
    <asp:ListItem Value="2">No</asp:ListItem>
    <asp:ListItem Value="3">Maybe</asp:ListItem>
    <asp:ListItem Value="4">I dont know</asp:ListItem>
    <asp:ListItem Value="5">Can you repeat</asp:ListItem>
    <asp:ListItem Value="6">the question</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
</asp:panel>
</InsertItemTemplate>

Code behind

    Protected Sub DDL_SelectedIndexChanged(sender As Object, e As EventArgs)

    Dim ddl As DropDownList = DirectCast(sender, DropDownList) 
    Dim listviewItemThing = DirectCast(sender.parent.NamingContainer, ListViewItem) 
    Dim tb As TextBox = DirectCast(ddl.NamingContainer.FindControl("TextBox2"), TextBox)

    If ddl.SelectedValue = 1 Then
        tb.Text = My.Computer.FileSystem.ReadAllText("E:\Users\han\Documents\Templates\1.txt")
    ElseIf ddl.SelectedValue = 2 Then
        tb.Text = My.Computer.FileSystem.ReadAllText("E:\Users\han\Documents\Templates\2.txt")
    ElseIf ddl.SelectedValue = 3 Then
        tb.Text = My.Computer.FileSystem.ReadAllText("E:\Users\han\Documents\Templates\3.txt")
    ElseIf ddl.SelectedValue = 4 Then
        tb.Text = My.Computer.FileSystem.ReadAllText("E:\Users\han\Documents\Templates\4.txt")
    ElseIf ddl.SelectedValue = 5 Then
        tb.Text = My.Computer.FileSystem.ReadAllText("E:\Users\han\Documents\Templates\5.txt")
    ElseIf ddl.SelectedValue = 6 Then
        tb.Text = My.Computer.FileSystem.ReadAllText("E:\Users\han\Documents\Templates\6.txt")
    Else
        tb.Text = ""
    End If
End Sub

Update 2

As per request please see attached screen shot of browser console error in debug on VS2013

enter image description here

And expanded error. enter image description here

Update 3

Added JQuery to try to force PostBack.

         function JsFunction() {
         __doPostBack('DLL_SelectedIndexChanged', '');
     }

ASP link to JQ

<asp:DropDownList ID="DDL" runat="server" Width="120px" OnSelectedIndexChanged="DDL_SelectedIndexChanged" AutoPostBack="true" CausesValidation="false" EnableViewState="true" onchange="javascript:JsFunction()">

Solution

  • You have correct code for your drop down list, so error in other place.

    As you see in error message: when you try submit form problem with HtmlEditorExtender.
    So just remove or disable it for quick fixing problem.

    As for error with HtmlEditorExtender we need a little bit information, of course, if you still need solve it.