PC Review


Reply
Thread Tools Rate Thread

Custom User Controls and dynamically created web controls events not firing

 
 
Nicole
Guest
Posts: n/a
 
      25th Sep 2003
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">
<asplaceholder id="UCContainer" runat="server"></asplaceholder>
<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
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
dynamically adding controls with events (but events are not firing) SevDer Microsoft ASP .NET 2 13th Nov 2007 06:33 AM
Handling Events for Dynamically Created Controls Nathan Sokalski Microsoft VB .NET 2 23rd May 2005 01:03 PM
Handling Events for Dynamically Created Controls Nathan Sokalski Microsoft ASP .NET 2 23rd May 2005 01:03 PM
Events for Dynamically created controls =?Utf-8?B?Qm9i?= Microsoft ASP .NET 1 3rd Sep 2004 04:35 AM
Events with Dynamically created controls. Dale Williams Microsoft C# .NET 1 1st Jun 2004 03:51 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:03 AM.