SelectedIndexChanged event masked

Discussion in '.NET' started by BernieDougherty, Sep 15, 2010.

  1. BernieDougherty

    BernieDougherty

    Joined:
    Sep 15, 2010
    Messages:
    1
    Hello all,

    I'm new to ASP.Net (using 2010 pro version) and I have a problem with ASP.NET that is giving me fits trying to solve it.

    I am trying to catch the SelectedIndexChanged event on the ddlParent DropDownList and use it's SelectedValue in code behind to repopulate the ddlChild DropDownList.

    I've distilled it down to some very simple test code and I'd appreciate some understanding of why this is not working as expected and what I should do to make it work (In VB please).

    I get the following compiler error:

    Compiler Error Message: BC30456: 'ddlParent_SelectedIndexChanged' is not a member of 'ASP.test_aspx'.

    Test Case code follows:

    <%@ Page Language="vb" AutoEventWireup="True" CodeBehind="Test.aspx.vb" Inherits="WebApplication2.Test" %>

    <head id="Head1" runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:DropDownList ID="ddlParent" runat="server"
    AutoPostBack="True"
    OnSelectedIndexChanged="ddlParent_SelectedIndexChanged"
    style="display: inline;">

    <asp:ListItem Text="-- Select --" Value="0" />
    <asp:ListItem Text="Parent #1" Value="1" />
    <asp:ListItem Text="Parent #2" Value="2" />
    </asp:DropDownList>

    <br />

    <asp:DropDownList ID="ddlChild" runat="server"
    style="display: inline;">
    </asp:DropDownList>

    </form>
    </body>
    </html>

    Public Class Test
    Inherits System.Web.UI.Page

    Private Sub ddlParent_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    If Not ddlChild Is Nothing Then
    ddlChild.Items.Clear()

    Select Case sender.SelectedValue
    Case 1
    ddlChild.Items.Add(New ListItem("Parent 1 Choice 1", 11))
    ddlChild.Items.Add(New ListItem("Parent 1 Choice 2", 12))
    Case 2
    ddlChild.Items.Add(New ListItem("Parent 2 Choice 1", 21))
    ddlChild.Items.Add(New ListItem("Parent 2 Choice 2", 22))
    End Select
    End If
    End Sub
    End Class




    Code will work correctly if I remove OnSelectedIndexChanged="ddlParent_SelectedIndexChanged" from ddlParent
    control and add a Handles clause to ddlParent.SelectedIndexChanged event in code behind like so:


    <%@ Page Language="vb" AutoEventWireup="True" CodeBehind="Test.aspx.vb" Inherits="WebApplication2.Test" %>

    <head id="Head1" runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">
    <asp:DropDownList ID="ddlParent" runat="server"
    AutoPostBack="True"
    style="display: inline;">

    <asp:ListItem Text="-- Select --" Value="0" />
    <asp:ListItem Text="Parent #1" Value="1" />
    <asp:ListItem Text="Parent #2" Value="2" />
    </asp:DropDownList>

    <br />

    <asp:DropDownList ID="ddlChild" runat="server"
    style="display: inline;">
    </asp:DropDownList>

    </form>
    </body>
    </html>

    Public Class Test
    Inherits System.Web.UI.Page

    Private Sub ddlParent_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlParent.SelectedIndexChanged

    If Not ddlChild Is Nothing Then
    ddlChild.Items.Clear()

    Select Case sender.SelectedValue
    Case 1
    ddlChild.Items.Add(New ListItem("Parent 1 Choice 1", 11))
    ddlChild.Items.Add(New ListItem("Parent 1 Choice 2", 12))
    Case 2
    ddlChild.Items.Add(New ListItem("Parent 2 Choice 1", 21))
    ddlChild.Items.Add(New ListItem("Parent 2 Choice 2", 22))
    End Select
    End If
    End Sub
    End Class



    To Further complicate the issue, I want to put both DropDownLists in a FormView (in my real code they are databound).
    When I put them in a Formview, the Handles clause no longer works and I still can't add the OnSelectedIndexChanged attribute to ddlParent without getting the same
    Compiler Error Message: BC30456: 'ddlParent_SelectedIndexChanged' is not a member of 'ASP.test_aspx'.

    Test case code for this is:

    <%@ Page Language="vb" AutoEventWireup="False" CodeBehind="Test.aspx.vb" Inherits="WebApplication2.Test" %>

    <head id="Head1" runat="server">
    <title></title>
    </head>
    <body>
    <form id="form1" runat="server">

    <asp:FormView ID="fvTest" runat="server" DefaultMode="Edit">
    <EditItemTemplate>


    <asp:DropDownList ID="ddlParent" runat="server"
    AutoPostBack="True"
    OnSelectedIndexChanged="ddlParent_SelectedIndexChanged"
    style="display: inline;">

    <asp:ListItem Text="-- Select --" Value="0" />
    <asp:ListItem Text="Parent #1" Value="1" />
    <asp:ListItem Text="Parent #2" Value="2" />
    </asp:DropDownList>

    <br />

    <asp:DropDownList ID="ddlChild" runat="server"
    style="display: inline;">
    </asp:DropDownList>

    </EditItemTemplate>
    </asp:FormView>

    </form>
    </body>
    </html>

    Public Class Test
    Inherits System.Web.UI.Page

    Private Sub ddlParent_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim ddlChild As DropDownList = fvTest.FindControl("ddlChild")

    If Not ddlChild Is Nothing Then
    ddlChild.Items.Clear()

    Select Case sender.SelectedValue
    Case 1
    ddlChild.Items.Add(New ListItem("Parent 1 Choice 1", 11))
    ddlChild.Items.Add(New ListItem("Parent 1 Choice 2", 12))
    Case 2
    ddlChild.Items.Add(New ListItem("Parent 2 Choice 1", 21))
    ddlChild.Items.Add(New ListItem("Parent 2 Choice 2", 22))
    End Select
    End If
    End Sub
    End Class

    I just can't seem to catch the SelectedIndexChanged event for the DropDownLists if I put the DropDownLists in a FormView.
    What am I missing here? Seems like this should be dirt simple to do. Any help would be greatly appreciated.
     
    BernieDougherty, Sep 15, 2010
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. |{evin
    Replies:
    7
    Views:
    574
    |{evin
    Nov 18, 2003
  2. =?Utf-8?B?bWV0cmlkZXZraw==?=

    Masked Edit Control

    =?Utf-8?B?bWV0cmlkZXZraw==?=, Dec 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    4,145
    Steve C. Orr [MVP, MCSD]
    Dec 3, 2004
  3. =?Utf-8?B?ZGF2aWQ=?=
    Replies:
    1
    Views:
    3,809
    Ken Cox [Microsoft MVP]
    Apr 19, 2005
  4. Dynamo
    Replies:
    2
    Views:
    443
  5. Ike

    Masked JTextFields

    Ike, Jun 7, 2006, in forum: Java
    Replies:
    1
    Views:
    406
    Paul Hamaker
    Jun 7, 2006
Loading...

Share This Page