Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > SelectedIndexChanged event masked

Reply
Thread Tools

SelectedIndexChanged event masked

 
 
BernieDougherty BernieDougherty is offline
Junior Member
Join Date: Sep 2010
Posts: 1
 
      09-15-2010
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">
<aspropDownList ID="ddlParent" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="ddlParent_SelectedIndexCha nged"
style="display: inline;">

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

<br />

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

</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_SelectedIndexCha nged" 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">
<aspropDownList 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" />
</aspropDownList>

<br />

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

</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>


<aspropDownList ID="ddlParent" runat="server"
AutoPostBack="True"
OnSelectedIndexChanged="ddlParent_SelectedIndexCha nged"
style="display: inline;">

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

<br />

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

</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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I use use Microsoft Masked Edit Control in ASP.NET web form =?Utf-8?B?ZGF2aWQ=?= ASP .Net 1 04-19-2005 01:12 AM
Masked Edit Box in VB Solar^ Computer Support 1 03-15-2005 03:34 PM
Masked Edit Control =?Utf-8?B?bWV0cmlkZXZraw==?= ASP .Net 1 12-03-2004 06:37 AM
Creating masked input for a form Dynamo HTML 2 11-17-2004 07:58 AM
Masked input control (or simulation of)? |{evin ASP .Net 7 11-18-2003 02:47 AM



Advertisments