How to call a function from one User Control from another User Control


I have one User Control in a page, the User Control has a button, when the user clicks on the button, I need to call a function within another User Control (on the same page).  I have made a function public, but I don't know see the function from the other User Control.

Can you help me please,

Thank you!


2/23/2008 2:53:27 AM 91979 articles. 4 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 47

have u added a delegate event for the button clicked like in the example below.


public partial class WebUserControl1 : System.Web.UI.UserControl


public delegate void ButtonClciked(object sender, EventArgs e);

public event ButtonClciked OnbuttonClicked;

protected void Page_Load(object sender, EventArgs e)



protected void Button1_Click(object sender, EventArgs e)


if (OnbuttonClicked != null)


OnbuttonClicked(sender, e);








public partial class WebUserControl2 : System.Web.UI.UserControl


protected void Page_Load(object sender, EventArgs e)



public void FunctionToCall()





//////uractauall page in which both control resides

public partial class Third : System.Web.UI.Page


protected void Page_Load(object sender, EventArgs e)


this.WebUserControl1_1.OnbuttonClicked+=new WebUserControl1.ButtonClciked(WebUserControl1_1_OnbuttonClicked);


public void WebUserControl1_1_OnbuttonClicked(object sender, EventArgs e)






//try to follow the example

this example is successfully calling the funtion in the user control 2

hope this helps


mark this as answer if the post helps

Saima Ghumman
--Mark the post as Answer if the Post helps you--
2/23/2008 3:58:12 AM

Hi Sam,

Thank you very much for your help! Your code worked great!


2/25/2008 12:54:41 AM

Similar Artilces:

want to call one function in one user control from another user control
hi i have two user controls info.ascx and personal.ascx i have a function like in info.ascx i have a function like showdetails() {   } now i want to access this function from personal.ascx can i do this ? thanks in advance. shwetaThanksshwetaIn a day when don't come across any problem -you can be sure that you are traveling in wrong path  you should better create a class where you will define the "functions" that you need in both files. declare "static" the function and call it like nameofclass.nameoffunction In a web project you can...

user control calling the function of another user control
I've created two user controls that are being placed on a aspx page: control1 and control2.  I would like to place a button on control1 and when the user clicks the button, I would like to call a function in control2.  How would I do this? TLAlway take some time for fun! Um, if this can be done then you would have to use the qualified name...   Control2.FunctionName(args) Otherwise, you can't do it this way, but you can do it by writing a Class in your App_Code folder and then have Control2 call said Function and then Control1 can as well. If this post helped you, Mark As Answer. ok, how about this.  I put control2 in a panel with visible false, and when I click the button in control1, I write something that allows me to show the panel with control2 in it?  TLAlway take some time for fun! Yep.  That can work. If this post helped you, Mark As Answer. I think what you're writing is that I can use the findcontrol that you wrote about before.  Can you show me the sytax for that? :) TLAlway take some time for fun!  Well, let me ask you something real quick, what exactly does this function accomplish?If this post helped you, Mark As Answer. One way I can think of doing it is:1. Expose a callable function of user control 22. Create a delegate and raise an event of control 1 that is handled by the page on which both the controls are3. When handling the event in the main page, call the function ...

Calling a User Control function from another User Control
I have several User Controls on my main page. They are basically DataLists that are filled contiginent on one another. How do I call a function in one User Control on the page from another one? I would not do that. I would more likely have the page control the interactions with both user controls, surface events on one or both of the controls and have the Page level code handle it. Generally, "Reaching Up" is not a great design. Linking the user controls in the way you are looking to will make them less generally usable, because they will depend upon each other. You could...

User Control calling function in another user control?
Hey there folks, I have a user control (UCInside, e.g.) inside another user control (UCOutside). I want to call a function that's contained in UCInside from UCOutside. Since UCInside has an associated class (let's call it ClassInside), I figured I could call the function by a simple ClassInside.UCInside.MyFunction(params)This calls the function, but I then can't seem to access any of web controls in UCInside from that function. Specifically, I have a RadioButtonList defined in UCInside. I want to retrieve, and then use, the selectedValue in MyFunction. I get an 'object referenc...

Updating a Label control in one user control from another user control
Hi all, I have a main page in my music store site that has 5 user controls on it with 1 always showing main content and the others being things like a shopping cart, "best sellers", genre list etc (a la amazon). From the main content control I want to be able to set some label controls in my shopping basket control but I just can't seem to work out the syntax for how to do this: Here's the code I'm using - I'm trying to go to the 4th user control on the page (my shopping basket) then find the appropraite label, cast it locally as a Label then update the value: Label _so...

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

Update one user control from another user control
I have two user controls (.ascx files) on one .aspx page. They are in some kind of master-detail relationship. When I select a row in the GridView in first control, second control is populated with editable data. After changing data and clicking update data IS saved but GridView in first control is not updated.How can I cause that data in first control refreshes, but to keep selected row selected?__Please mark post as answer if it helps, if not come back and ask again! Hi,You need to re-bind the GridView with the updated data source so that it reflects the latest changes. Regarding the cur...

Calling user control within another user control
I want to call one user control within another user control, but I get all sorts of errors when I try to do this. Is this possible ? if so how to go about it. {code} <%@ Control Language="C#" AutoEventWireup="true" CodeFile="i_top.ascx.cs" Inherits="i_top" %> <%@ Register TagPrefix="agg" TagName="siteowner" Src="~/templates/i_siteowner.ascx"%> <div id="navbar"> <h2 class="hide">Site wide navigation</h2> <ul> <li><a href='~/default.aspx' id...

How to call function in one usercontrol from another user control
hi everybody i have one function like bindcs() {   } in my one user control. now i want  to call this function from my another user control. i tried to do this by findcontrol but it get the whole control i dont get it its function. can anyone help me? thanks shwetaThanksshwetaIn a day when don't come across any problem -you can be sure that you are traveling in wrong path You will need to declare the method as public and then cast the control that you get from FindControl to be the type of the user control. A good approach for this is to implement an event on t...

How to access one user control from another user control on same page
hi,I have two usercontrol on same page. 1.ascx and 2.ascx on abc.aspx . Now I need to access dropdown on 1.ascx frm 2.ascx . Plz help me how can i do this?I have tried Page.findcontrol but as a user control inherits usercontrol class and not page class . its not giving reference to proeprty Page.Findcontrol. I can do page.findcontrol on aspx page but I need to do it on ascx only.plz helpregards,max   Hi Max, you have to expose your DropDownList as a public property which lays inside usercontrol 1. Example: 1 class MyUserControl1 : UserControl 2 { 3 4 p...

Pass value from one User Control to another User Control
I have tried to pass value from one user control to another user control. Because of Page Auto Postback, Contrls are load before page is loaded. So I get the value in 2nd UC after one more post back operation. I have visited many suggessions but I cant solve this. Is anyone can help me to solve this. Thank U Muhmmad Fakhrul HossainEmail: mfhossain@gmail.comPhone: +88 01715 111512Web: You'd have to do that through the parent probably in it's Page_Load event handler.   userControl1.publicProperty = userControl2.publicProperty;  ...

How to bind grid of one user control from another user control
i am having a data grid in one user control say A and there is another user control say B when ever i add some vale in B that is inserted in to database and i want to call A's bind method of grid ... Please help me Nilesh Garg Well, If you can get a hold on Page control of user control then you can easily deal with the othe ruser control. Try something like this Me.Parent or Me.Page or somethinglike this to take hold on Page control and then you can easilly get instance of othe ruser control. Alternatively you can have one shared method somewhere in some class. Call it and i...

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

Problem sharing a webcontrol in one User Control with another User Control...
Hi,I need to "share" a button in one User Control with another User Control. I have been trying to make it work for a long time, but I am nearly giving up. Please help! (I am coding in ASP.NET 2.0 C#)I have a main page (default.aspx) that contains two User Controls (mainUC.ascx & buttonUC.ascx).At first the User Control mainUC contains text (textHolder) that is clickable and the User Control buttonUC contains a button (editButton) that is disabled.The functionality I need is:1. When I click the text (textHolder in mainUC) the button (editButton in buttonUC) is enabled. This wor...

How to a call a function from a user control's parent user control ?
 hiHow to a call a function from a user control's parent user control ? for example i have one user control an tree in user control i add other user control in place holder for add node for tree Now how i can rebind tree when i add new node thank a lot  You can rebind the whole page if you do a Page.DataBind(). Alternatively, if you need to bind only one specific control in the parent, you can create an interface such as IMyParentUserControl, create a method definition within it such as:public interface IMyParentUserControl{     void DoMyBinding();} a...

Call function of 1 user control from a different user control on same page.
Hi, Is it possible to call a public function of 1 user control from another user control on the same page? if so, how would i go about doing so. I will provide any other info you require. Thanks for your time Lee Have you tried calling usercontrolA.publicFunction?  That will not work. The code behind of UsercontrolA does not recogise the code behind of UsercontrolB. The page both of these controls are on WILL recognise both of the controls functions, but the user control does not know what page it is on until it runs. Why dont you create a class with this functio...

Calling a user control method from another user control code behind
Hi there,In a webform I have a FormView. The ItemTemplate contains two users control, UC1 and UC2.  When certain event fires in UC1´s code behind, I need to call a public method in UC2. So I think from UC1´s event code I need to find the container FormView first, then find the ItemTemplate and finally find UC2 inside it, and then call UC2´s method.Is that the way to go? I would appreciate a lot some ideas/suggestions/C# examples on how to do this.Thanks in advance.    You can create a public method in a separate class so that you can call that method anywhere in your codes.....

Reading a user control from another user control
I have 2 user controls on a page. The first one (UserControl1) is called "header.ascx". This contains a drop down list box called "ddlLang". The other user control (UserControl2) is called "menu.ascx". I want this user control to check the value of "ddlLang" in the header user control. How do I do it? Quite stuck at the moment! Thanks hi, even i am stuck to the same problem. what i came to know is 1) You have to find the page of control....(or if u want to hardcore it say its menuholder.aspx) 2) then u can use menuholder.use...

Access User Control From another User Control
 ASP.NET 2.0/VB.NET I have a number of pages all with two user controls on them.  I need to access controls/properties from one user control from within another.  I've tried the following from one of the user controls: Dim pg as Page = cType(Me.Page, Page) pg.FindControl("myControl")  'Returns nothing pg.form.findControl("myControl")  'Returns nothing   I also have public properties declared but I can't see those either (I also tried public shared property).  Can anyone help with the syntax?   thanks, Scott ...

Updating a User Control from another User control
I have a web page that has three frames: Header, Nav, and Content. In the header frame, I have a user control for the breadcrumb text (something like "Home : Cases : Jones Case : Contacts") that needs to be updated based on information sent from another user control which is in the Content frame. Is this possible?...

Is it possible to handle an event raised in one user control that is contained within another user control?
I have a user control that contains a standard dropdownlist. I created a public event (listchanged) within this user control that I raise when the selectedindexchanged event of the dropdownlist is fired. Within the parent usercontrol that contains the usercontrol above, I created an event handler that handles listchanged. The problem is, this handler is never called. The raiseevent in the child control doesn't throw any errors so i am stumped as to why this is. Is it just not possible to catch usercontrol events within another user control? I may just not understand...

User Controls in User Controls?
I have the follow set up and it is throwing an error "Unhandled error loading module" ... is there some trick to this that I don't know?I have a project A that uses controls from project B (project B is just a project with all my user controls used through out other modules).  project A uses user control 1 from project B with out any issues at all - great.  But then I wanted to add user control 2 to user control 1 and that is when I get my error.  In fact I don't even have the user control 2 in user control 1, just when I put the register part into user control 1 is when it al...

User control in a user control
Hello all, I have created a user control with some checkboxes, and public properties to get the values of these checkboxes. I have also created a second user control using the first user control; this second control also access the public properties of the first one. My problem is when I implement the second control in an aspx page, if I click at runtime the checkboxes in the first control, I am able to access its public properties from the methods of the second control but the values of these properties are wrong. while at design time, I do not have this problem. Than...

user control to user control
I have an aspx page that have a "Register" directive to two usercontrol called rptMaster.ascx and rptDetail.ascx. I'm trying to set up a Master-Detail relationship and wish for the rptMaster.ascx to trigger and event from a dropdownlist and for the rptDetail to be listening for DropDownList event. I believe I have gotten the events part okay with help from this articel but my declaration for a private statement to my rptMaster class is producing an error. I'm using beta 2 of and I 'm having trouble getting a reference TO ...

Web resources about - How to call a function from one User Control from another User Control -

Talk:Trigonometric functions - Wikipedia, the free encyclopedia
This article is within the scope of WikiProject Mathematics , a collaborative effort to improve the coverage of Mathematics on Wikipedia. If ...

Resource sector may outsource finance functions to Asia
Outsourcing financial functions to Asia is one tactic struggling Australian energy and resources companies may use this year to survive the slump ...

Media devices sold to feds have hidden backdoor with sniffing functions
... AMX NX-1200 , a programmable device used to control AV and building systems. The researchers first became suspicious after encountering a function ...

A Non-Sokratic Dialogue on Social Welfare Functions: Hoisted from the Archives from 2003
**[A Non-Sokratic Dialogue on Social Welfare Functions: Hoisted from the Archives from 2003]( ...

Drop Point Knives: Function, Fit, Timeless
Drop Point Knives: Function, Fit, Timeless

Here's how squads and iron sights will function in Rising Storm 2: Vietnam
... roles and create a squad, and the creator can name, lock, or invite others to their little group. The more an outfit fills up, the more functions ...

Don’t tase me, bro: Study shows being shocked by a Taser disrupts brain function
Researchers at Drexel shot a bunch of college students with 50,000 volts. The result? Short-term declines in cognitive function comparable with ...

Slim and Soft Cover-Ups: Protecting Your Laptop with Function and Style
I’m a klutz. My phone has the scars and cracks to prove it. Likewise, my laptop bears scratches and dents in the lid, from me banging it into ...

A 3D Printed Jet Engine Appears to Function
... jet engine . You may remember seeing a 3D printed jet engine grace our front page back in October. That one was beautiful didn’t function . ...

Supreme Court Justices Can Still Function With Eight
... Domain,] But as to whether the remaining Supreme Court justices will be able to function ...

Resources last updated: 2/15/2016 12:19:07 PM