I have a peculiar problem and since I am just starting to use .net I
am confident I am doing something wrong, but I can't see it and I've
wasted a lot of time so far trying to figure it out. Hopefully one of
you can figure it out.
I have a custom User Control and I am dynamically creating a
RadioButtonList. If I remove the custom user control from the page the
RadioButtonList works as expected and correctly. However, once I add
the custom control, it does not fire the SelectedIndexChanged event.
Below is the code. If all I do is remove: "<UC:TOPMENU id="TopMenu1"
runat="server"></UC:TOPMENU>", everything works properly. If it's
there, "rMrktChooser_SelectedIndexChanged" is never executed. I've
tried breakpoints, etc. And, AutoPostBack is True of course.
Thanks in advance!
***** ASPX page *****
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="DefaultPage.aspx.vb" Inherits="WebApp.DefaultPage"%>
<%@ Register TagPrefix="UC" TagName="TopMenu"
Src="Controls/top_menu.ascx" %>
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp

laceholder id="UCContainer" runat="server"></asp

laceholder>
<UC:TOPMENU id="TopMenu1" runat="server"></UC:TOPMENU>
<asp:Label id="Label3" style="Z-INDEX: 104; LEFT: 23px; POSITION:
absolute; TOP: 163px" runat="server"
Width="368px" EnableViewState="False"></asp:Label>
</form>
</body>
</HTML>
***** CODE-BEHIND *****
' Added by hand for access to the form.
Protected Form1 As System.Web.UI.HtmlControls.HtmlForm
' Added by hand; will create instance in OnInit.
Protected WithEvents rMrktChooser As
System.Web.UI.WebControls.RadioButtonList
Protected WithEvents UCContainer As
System.Web.UI.WebControls.PlaceHolder
Protected WithEvents Label3 As System.Web.UI.WebControls.Label
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
rMrktChooser = New RadioButtonList
rMrktChooser.Items.Add(New ListItem("By Market", "Market"))
rMrktChooser.Items.Add(New ListItem("By DRA", "DRA"))
rMrktChooser.ID = "rMrktChooser"
rMrktChooser.AutoPostBack = True
rMrktChooser.EnableViewState = True
UCContainer.Controls.Add(rMrktChooser)
InitializeComponent()
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not IsPostBack Then
' Set the initial properties for the radion button list.
rMrktChooser.SelectedIndex = 0
End If
End Sub
Private Sub rMrktChooser_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
rMrktChooser.SelectedIndexChanged
Dim radioSender As RadioButtonList
Dim strRadioID As String
radioSender = CType(sender, RadioButtonList)
strRadioID = radioSender.ID
Select Case strRadioID
Case "rMrktChooser"
Label3.Text = "RadioButtonList text was changed"
End Select
End Sub