Custom User Controls and dynamically created web controls events not firing

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 some code. If all I do is remove: "<UC:TOPMENU id="TopMenu1" runat="server"></UC:TOPMENU>", everything works properly. If it's there, "rMrktChooser_SelectedIndexChanged" never is 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:placeholder id="UCContainer" runat="server"></asp:placeholder>
<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
0
nmarz
9/25/2003 8:12:59 PM
asp.net.web-forms 93655 articles. 6 followers. Follow

0 Replies
1365 Views

Similar Articles

[PageSpeed] 57
Get it on Google Play
Get it on Apple App Store

Reply:

Similar Artilces:

Problem in accessing web form data in user controls when create user control dynamically
HI. I have a problem using web user control. I designed a user control named NewsForm. This user control contains some web form elements like <asp:textbox>. When I add it in an .ASPX page, all things may be true. I can know which user filles in textbox (for example and other controls) <%@ Register TagPrefix="uc1" TagName="NewsForm" Src="NewsForm.ascx" %> and <UC1:NewsForm id="newsForm" runat="server"></UC1:NewsForm> But when i create it in code behined dynamically, however user control has web form controls but their value are blank for example //aspx co...

Event not firing with Dynamic Controls in a Custom Web Control
I'm creating some LinkButtons on the fly (on Load) and they show up just fine.  The problem is that the AddHandler event I created is not firing.  I'm at a loss...have read a ton of articles today, but just can't figure this one out.  Please help a newb! :-)Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e) EnsureChildControls() If Me.Page.IsPostBack Then Me.Units = Me.rblUnits.SelectedValue 'If there is text in the txtSearch TextBox, then search for the new loc...

Web User Control dynamically generated control events won’t fire.
I hope someone can give me a hand on this one.   This is what I am trying to do:   We need to create a report. We are using a Repeater control to generate a custom grid. The columns and data fields won’t be known until run-time.   I’ve created a WebUserControl which contains a repeater control.   At run-time, I dynamically create templates for the header and data items. On the header template I want to use a LinkButton so that data can be sorted when the user clicks on one of the header columns.   In my Header Template class, I have a reference to a list o...

Use Web Custom control or Web User control?
Friends,  I have a generic aspx page and its functions which is used in many .NET web application. The generic page contains a HTML Div control, server drop down list, server buttons, server textbox and it have different server and client functions to do its tasks for calling aspx pages in web applications. My problem is I do not know whether I should make that generic page as a web user control (but this is tedious because all other application folders must store frontpage aspx and code behind files of the generic page) or as a web custom control (This seems to be good beca...

Web User Control to Web User Control...
Hi, I have 2 User controls on a page and want Control1 to call a method of Control2. Is this Possible? Example: Con1 = Datalist showing products, each with a Quantity Box and a Button. Con2 = Repeater showing Cart Preview (name, Price) in page.aspx. When I click on the button on the DataList in Con1 it adds the item into the Session based Cart. However it does not update the Cart Preview. I need to call BindPreview() in Con2 in order to update the Cart Preview... Does that make sense? argh! any help much appreciated! PeteWeb Design Nottingham, UK Well I can call BindPreview() from m...

Server Web User Control or Web Custom Control
Ok, I made a DataGrid I like, stuck it in a Web Control Lib, and then to my toolbar. Now I want to take my nice little control and add it to a greater control, maybe place some buttons around it etc. I could always inherit from it in a new custom control and dynamically add the buttons, but I thought about using a Web User Control. I thought I could easily create a Web User Control, drop on my grid and the buttons on a form, and expose some properties and events, but once I got into it, I got a feeling that this isn't what a Web User Control is for. When designing a control li...

What is the difference between a Web User Control and a Web Custom Control
Hi ,please could you answer for the following question with example. i know wht they are. but i want to know hw they are existing in web pages with simple example. What is the difference between a Web User Control and a Web Custom Control?  Thanks in AdvanceDilip    Check this out .... hope these might help you out... http://support.microsoft.com/kb/893667http://msdn2.microsoft.com/en-us/library/aa651710(VS.71).aspx itsUrDAY  Hi, See the following URLs: https://msdn2.microsoft.com/en-us/library/fb3w5b53(VS.71).aspx(Introduction to Web User Contr...

Master Page, Dynamically creating web user control and Event not firing
I am sure all of you have seen this article by Scott Allen. Great Article http://odetocode.com/Blogs/scott/archive/2006/04/12/3271.aspx In here I saw a comment Thursday, May 04, 2006 11:50 AM by Priya # re: The MasterPage Article I Thought I’d Never Finish Good one. I have a custom control with a button. The button click event fires if the page is without master. But, after the master is added, the event does not fire. Can you please help with this? Thanks a lot. Do any of you know what the answer to this problem is. I have a similar issue. Let me explain issue in detail. I have a mast...

access controls on web user control x from web user control Y
I have 2 web users controls in a page and I would like to get or set the selected values of a few dropdown boxes on web user control X from web user control Y and I also would like to know how to access functions that are on a web user control X from a web user control Y, is this possible? How can I do it? User can access and set the values of the User Control from .aspx page through properties,using javascript and in code-behind of aspx page.The details of it are shown below Using PropertiesIf the Sample.ascx control has two textboxes and submit button.You can access the valu...

custom web user control and web form
Guys,          I am trying to develop a context menu control for all of my pages. what i am trying to do is that i want the control to pick a datasource from the markup and then check whether its an xml file or a datatable. I created a class called datasource.   /**************************DataSource Class****************************/  public class DataSource { /// <summary> /// This is to identify unique elements from the markup /// </summary>protected string _ID; /// <summary> /// This will be the Datasource ID e...

User Control controls not created when dynamically creating user control
  Have created a user control for displaying and editing a dynamically number of values. The user control contains two labels and an edit box. When dynamically loading the user control I get an error when the control itself tries to change setting on the fields within the user control.   Why doesnt this work? It works okay if I dont load it dynamically but create a user-control-instance in the aspx-page but thats no solution.   Thankyou!     Here is my code:   ucDataValue.ascx   <%@ Control Language="C#" AutoEventWireup="true&...

Web Custom Control within a Web Custom Control
I was wondering if this can be done and how. I've created a simple custom control that displays a header which is my first custom control. So I'm just a baby when it comes to this.. Within the header I currently have a property for breadcrumbs which is a string. What I would like to do is have the breadcrumb property  be a Link Button List. I did find a custom control of a Link Button List which is exactly what I wanted. My question is how can/do  I include this into my custom control? Can it done? How? Please help? I'm at a lose here.   Susan You should be able to do ...

web controls and web user control
i have a problem in a web form , I have a webform that contains a web user control which in turn contains a html input form ,the web control events don't fire up ,When I click button ,no effect ,I don't know what is the effect of the html form which is in the web user control on the web controls in the web form ?? can any one help me the web control event should be handle in the code behind page, is the event handler for the button you are clicking registered? You can try double clicking the button, should give you the default btn_click event handler in code behind. Also, make ...

Custom Databound Web Control with Dynamically Created Controls.
I have a conundrum, or perhaps I'm overcomplicating something that shouldn't be this difficult.  Likely the later.  I have created a control that inherits from WebControl.  I include it on my page (CDD), and on Page_Load set it's datasource and a few important properties. CDD.DataSource = resourcesXml; CDD.Levels.Add("/Resources/Resource", "RootDesc", "RootResourceID"); CDD.Levels.Add("Category", "CategoryDesc", "CategoryResourceID"); CDD.DataBind();  The problem is, that the control has ...

Web resources about - Custom User Controls and dynamically created web controls events not firing - asp.net.web-forms

Placebase team at Apple file “Schematic Maps” patent dynamically detailing important data
In a report from Computerworld way back in 2009, we learned that Apple had quietly acquired Maps API company Placebase. Then, founder of Placebase ...

Apple's Lightning port dynamically assigns pins to allow for reversible use
... a closer look at how Apple's new Lightning connector works, and has come to the conclusion that the 8 pins on each side of the plug are dynamically ...

In a dynamically typed language, is it a bad idea to return different data types?
In some cases, returning different types from a single function works.

Urlbox Launches Screenshots-as-a-Service Platform to Dynamically Update Galleries
... changes. Launched yesterday, Urlbox allows anyone with a gallery displaying website screenshots to automate the process and keep them dynamically ...

Everything.me launcher dynamically adapts to what you’re doing right now
... phone according to what you’re doing. Perform a search for ‘football’ and your background will change to the NFL logo. A launcher that dynamically ...


A YouTube Experiment Resizes the Player Dynamically
There's a new YouTube experiment that changes the video player's size, depending on the browser window's size. When resizing Chrome's window, ...

Apple Granted “Dynamically Changing Cursor for User Interface” Patent, Originally Filed in 2003
... a utility patent that covers the use of the mouse cursor that changes according to the context of the task it is engaged in. Called a “Dynamically ...

Atmel's FPSLIC II Dynamically Reconfigurable SoC Supports "Silicon-Sharing" For Peripherals & Interfaces ...
Silicon-Sharing Fits 200K Gate Design into 40K Gate FPSLIC II's, Cuts Power Drain by 97%

Everything.me Launcher Wants to Dynamically Change Phones Based on Location, Interests, and Mental State ...
What if your phone’s launcher dynamically changed based upon interests, your location, or topics you had in mind at a specific moment? A new ...

Resources last updated: 12/7/2015 12:41:14 PM