access user control controls


 I have a user control and on it button. When I place ascx control on a aspx page, is there a way to access button events in user control. Something like:



9/15/2008 6:04:27 PM 93655 articles. 6 followers. Follow

5 Replies

Similar Articles

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

Here's an example for you:


<%@ page language="C#" masterpagefile="~/MasterPages/Default.master" autoeventwireup="true"
	codefile="CaptureEventInParent.aspx.cs" inherits="UserControls_CaptureEventInParent"
	title="UserControls: Capture Event In Parent" %>
<%@ register src="ButtonUserControl.ascx" tagname="ButtonUserControl"
	tagprefix="uc" %>

<asp:content id="Content1" contentplaceholderid="ContentPlaceHolder1" runat="Server">
	<uc:buttonusercontrol id="ButtonUserControl1" runat="server" onclick="ButtonUserControl1_Click" />


using System;

public partial class UserControls_CaptureEventInParent : System.Web.UI.Page
 	protected void ButtonUserControl1_Click(object sender, EventArgs e)
		Response.Write("I was clicked!");


<%@ control language="C#" autoeventwireup="true" codefile="ButtonUserControl.ascx.cs"
	inherits="UserControls_ButtonUserControl" %>

<asp:button id="Button1" runat="server" text="Button" onclick="Button1_Click" />


using System;

public partial class UserControls_ButtonUserControl : System.Web.UI.UserControl
	public event EventHandler Click;

	protected void Button1_Click(object sender, EventArgs e)
		if (this.Click != null)
			this.Click(this.Click, e);

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

9/15/2008 6:30:36 PM

you could do the following this is in C# but you can convert it to VB easily

Button btn = (Button)this.usercontrol1.FindControl("button1");
Please mark post as answer - Progressive Web Methodologies

My Blog
9/15/2008 6:31:02 PM


Although I didn't initiate this thread, thanks for this. Can I ask one thing. Is it possible to make the example less ambiguous. Both the user control and the parent page's event handlers are called click.

Having a similar need, I tried this but it didn't work. My this.Click was always null. Does the Click in the if statement refer to the protected event or the public event?



9/15/2008 7:20:50 PM

You can name the Event whatever you want.

public event EventHandler WhatEverYouWant;

And yes, the If statement refers to the custom public event.

Thanks, Ed

Microsoft MVP - ASP/ASP.NET

9/15/2008 7:40:28 PM


You can name the Event whatever you want.

public event EventHandler WhatEverYouWant;

And yes, the If statement refers to the custom public event.


I figured out that my public event was always null because this is a dynamically created user control and I had to assign the public event to a handler on the parent page. Once I did that, it worked. ie:


                ASP.cuisenaire_cms_taskbar_ascx TaskBar = (ASP.cuisenaire_cms_taskbar_ascx)LoadControl("TaskBar.ascx");
                TaskBar.WhatEverYouWant +=new EventHandler(TaskBar_BubbleClick);

9/15/2008 8:07:35 PM

Similar Artilces:

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

How to access individual controls from a form containing the web user control containing those controls
 Below is a block of code in my .aspx form named default.aspx. In this form I load a web user control. I then add it to a place holder control.(Lines 3 and 4 below) So how do I access the individual controls in my web user control? I want to set the properties on those controls, but I am baffled as to how to access the control. For example I have a text label control named "label3". How do I access this control. Because for example, under certain situations I want to hide that control. ( Label3.Visible = false;)  1    if(!Page.IsPostBack) 2&nb...

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

User Control Within UserControl
If I have a user control A and then inside it a user control B embedded/referenced within it.  User Control A has a panel defined (cpeNewUser) that I want to manipulate from the code behind of User Control B based on some event that happens.So putting this in my code behind of User Control B won't work as it has no idea of cpeNewUser:cpeNewUser.Collapsed = true;So is it because only at runtime they are married up and because of this you cannot access each other's objects at compile time?  How would I get this to work becuase I'm using all user controls inside a AJAX Too...

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

How to access a user control from another user control in a Wizard control
My page has a wizard control and each step is a user control.  I could find the value of a control in step1 user control in the wizard page but not in step2 user control.From wizard.aspx.vb – it worksDim m_title As DropDownList = CType(Me.PersonalBox1.FindControl("ddlTitle1"), DropDownList) Question:How can I find the value of a control(textbox or dropdownlist)in step1 user control from step2 user control? I want to find “PersonalBox1.FindControl("ddlTitle1")” from Step2 AddressBox1. I have tried several ways to access it but no luck. From AddressBox.ascx.vb –...

Accessing form controls from a user control
What's up all,I have a user information form in a user control(standard input fields). When I used use VS 2003 I could set the declared Web Controls to "public" so I could access them from the page referencing the user control..But with VS 2005 I can't seem to find a way to access the declarations of the individual Web Controls to make them public.Would it be a better idea to make a property for each control, within the user control and make those public to retrieve the data? Thanks!Gary It's a good OOP practice to create a public property within the UserControl to expose access...

Access SqlDataSource on Web Form from a Web User Control...
Hello, I want to access a SqlDataSource on a Web Form fromout. a Web User Control. To do this, I have in my code behind of the Web User Control the folowing code: DropDownList1.DataSource = (this.Page.FindControl("SqlDataSource3") as SqlDataSource);DropDownList1.DataTextField = "Name;DropDownList1.DataValueField = "NameIDropDownList1.DataBind(); But, the control (ic. SqlDataSource3) is not found. Even other controls like labels and buttons are not found with the FindControl. What am I doing wrong? Thanks Andromedaris     This is not much of a surprise,...

Access a Web User Control Method from a Web Form
I'm trying to pass the Selected Index value from a web user control in a web form to the user controls selectedIndexchanged Sub.  I can't seem to figure out how to pass the information that I need to the user control and have it execute the sub routine. In the SelectedInedxChanged Sub I have a switch Statement and I want to get the index value from the web form where the user control is located and compare it to each case and then to have it execute the code for the case that it matches. What do I need to do? Hi, I am not sure if I understood your question correctly. I su...

Accessing Web Controls within a User Control
Hi, I've built a page which contains a user control. The contents of this user control is a dynamically-built series of radiobuttonlists. What I need to be able to do is access these radiobuttonlists from the code behind the outer page, the one containing the user control. However, it seems as though I cannot do this. Looping through control.controls I can see a placeholder control within my user control, but not the dynamically generated radiobuttonlists beneath it. As far as I'm aware you can usually access dyanamically generalted controls by using control.controls, but this seems di...

Access parent control in Web user control
Iam using Web User Control. I need to assign some values to the parent control. Is it possible to do it?. Thanks in advance. Cheers!!! Prashanthan KThanks! Prashanthan K I got the solution for this. Me.Parent.FindControl("") returns the parent control. Thanks Prashanthan KThanks! Prashanthan K...

Accessing a control inside a Web User control
Hello, I have a bunch of controls inside a Web User Control (.ascx) file. This user control is used inside an aspx page. I wanted to access the controls inside the ascx from the codebehind for aspx (have to bind a drop down list inside the ascx from the codebehind for the aspx) How can this be done? ...tried using FindControl method but it somehow returns 'null' Thanks in advance,Kumar A better solution is to expose a property from the User Control (perhaps a DataSet) and then fill in that DataSet and bind the control inside the UserControl and have the UserControl do the work,...

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

Unable to access user control's user control's function\property from another user control
Hi, I used to call an user control's user control function as stated below from my user control in ASP.Net 1.1 wucCompany.wucEmployee.GetEmployeeSomething() After migrating to ASP.Net 2.0, I am unable to use any properties/functions(even the public ones) of the user control's User control's from another user control.  The way I have to do is create property\function in wucCompany which calls the wucEmployee's property\function and call the wucDepartment.GetEmployeeSomething().Since I need to do this change in too many places, I can...

UpdatePanel within a web user control resets data of controls outside the user control
Hello, I have a usercontrol on my page which displays a running marquee text. It makes use of an UpdatePanel (within the user control) to refresh the marquee text (within the updatepanel) at periodic intervals. For this I added a timer control and its tick event as an async postback trigger for the UpdatePanel. I have a lot of textboxes and dropdown list boxes (all with runat=server) on the page outside the above user control. These are also contained in different UpdatePanels. Problem is, when the user control does a postback to refresh the marquee text, it causes some of...

Web resources about - access user control controls -

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

The US needs gun control to protect children like my grandson, killed at Sandy Hook
Motives do not matter to the dead. They don't matter much to survivors, either.

Church is about power, money and control
Readers react angrily, and sceptically, to the news that Cardinal George Pell may not be able to return to Australia to attend the royal commission ...

Microsoft Band updated to include music controls and inactivity alerts
... Microsoft Band came out, the company is adding functionality with a small software update. The two biggest features of this update—music controls ...

Control a car's features with a glance? Not science fiction
Filed under: Emerging Technologies , Infotainment , Technology Press a button to change your car's climate controls? Turn a knob to view your ...

"... Trump owns and controls the media... they can't not cover him... his audience is bigger than theirs ...
... their army (i.e., the media) can't take out their enemy. They don't have the slightest idea what to do.... The media, in their own minds, controls ...

How to control your iPhone by just tilting your head
... the best sight, hearing, or motor functions to still use iOS to its fullest capabilities — but they can also be used to customize your controls. ...

How to use iOS or Apple Watch as remote controls with Apple TV
... new feature for Apple TV owners using Apple Watch, iPad or iPhones last week – the capacity to use your iOS device as a remote control for your ...

White House: We’re Not Going To Wait Until Something Happens To Pass Gun Control
Reporter: 'Where any of the recent mass shooters on the no-fly list?' Earnest: 'Not that I'm aware of'

Bart & Fleming: Don’t Come To Year-End Movies To Get Laid; Time For Movies About Gun Control Debate?
Peter Bart and Mike Fleming Jr. worked together for two decades at Daily Variety . In this weekly Sunday column, two old friends get together ...

Resources last updated: 12/14/2015 5:49:12 PM