Hej
I'm trying to set up a dropdownlist as a user control and everything has been going ok until trying to get the SelectedIndexChanged event to fire - in fact its not even the event that I need to get working but rather having access to the SelectedItem.Value - I've been working with ASP.Net for a while now but I'm new to user controls (really looking forward to using their potential) - I've followed several tutorials and forum posts but I just can't figure out what I'm missing - I've supplied the majority of the code I'm using
'USER CONTROL
Protected WithEvents ddl As System.Web.UI.WebControls.DropDownList
Private SelValue As Integer
Public Event ListChanged(ByVal sender As Object, ByVal e As ListArgs)
Protected Sub ddl_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddl.SelectedIndexChanged
Dim la As New ListArgs
la.itemValue = ddl.SelectedItem.Value
SelValue = ddl.SelectedItem.Value
RaiseEvent ListChanged(sender, la)
End Sub
Public Class ListArgs
Inherits EventArgs
Public itemValue As Integer
End Class
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
'Data binding code is here
End If
End Sub
'as you can see I tried different techniques with this property
Public Property SelectedItemValue() As Integer
Get
Return SelValue
End Get
Set(ByVal Value As Integer)
SelValue = Me.ddl.SelectedValue
End Set
End Property
<asp:dropdownlist id="ddl" runat="server" AutoPostBack="True"></asp:dropdownlist>
'Web Form
'These are the methods that I expected to be working but ucDropDownList1_ListChanged never seems to be called
Private Sub Button1_ServerClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.ServerClick
Response.Redirect("newPage.aspx?ID=" & ucDropDownList1.SelValue)
End Sub
Private Sub ucDropDownList1_ListChanged(ByVal sender As System.Object, ByVal e As LaResBeer.ucDropDownList.ListArgs) Handles ucDropDownList1.ListChanged
Label1.Text = e.itemValue.ToString
ucDropDownList1.SelValue = e.itemValue
End Sub
<%@ Page Language="vb" AutoEventWireup="false"%>
<%@ Register TagPrefix="uc1" TagName="ucDropDownList" src="ucDropDownList.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
.....
<uc1:ucDropDownList id="UcDropDownList1" runat="server"></uc1:ucDropDownList>
hopefully somebody can see what I'm doing wrong and help me fix this - thanks