want to call one c#.net function in one user control from another user control


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.




In a day when don't come across any problem -you can be sure that you are traveling in wrong path
7/2/2008 7:15:45 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

4 Replies

Similar Articles

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

 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

7/2/2008 8:40:08 AM

In a web project you can't reference a Page or User control class from a stand-alone class.

If you want to reference the User Control class, you need to create a web application project.

See the comparison of both project types - http://msdn.microsoft.com/en-us/library/aa730880(VS.80).aspx#wapp_topic5

My Blog
7/2/2008 8:47:14 AM

Assuming showdetails() is a public non-static method in info.ascx, you can only call it using an instance of the info.ascx User Control.

Therefore, in order to be able to call info.ascx's showdetails() in a response to an event in personal.ascx, you'd have to do it in the code behind of a page which contains instances of both of these User Controls. If you would like to do it consistently over several pages, I would recommend either you add an instance of info.ascx inside personal.ascx, or better yet build a 3rd User Control which contains both of them and place it in the relevant pages.

If any further clarifications are needed, please let me know.


7/2/2008 8:49:15 AM

Hi shweta,

Yes it is possible to call function of one ascx control from another.

Suppose u have one page in which u have dropped 2 ascx control.

1. a.ascx - Control Id in Page : a1 - Class Name : _a

2. b.ascx - Control Id in Page : b1 - Class Name : _b

In a.ascx

Public Sub CallFromOutside()

End Sub

In b.ascx

DirectCast(Me.Parent.FindControl("a1"), _a).CallFromOutside()

Please mark as Answer if it helps u. Thanks!

Parth Patel
Techsture Technologies
Software Developer
7/2/2008 9:26:30 AM

Similar Artilces:

How to call C#.net 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 call a function from one User Control from another User Control
Hi, 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! Aldo have u added a delegate event for the button clicked like in the example below. ////////WebUserControl1 public partial class WebUserControl1 : System.Web.UI.UserControl {public delegate void ButtonClciked(object sender, EventArgs e); public event B...

I have a web user control being used by another web user control, but the one being used will not display the labels in the resx file.
I am using DotNetNuke version 3.13 (might be 3.013) on a Window's XP machine, SP2. I have what I find to be an extremely odd situation. I have a project called TDS.Controls. This project is a web control library. Each control has its own resx file, which is located in the App_LocalResources directory. Each control inherits from Framework.UserControlBase, just like DotNetNuke's User control in DNN\Controls\User.ascx.vb. As a matter of fact, this control is doing the exact same thing I am trying to do. It is a web user control with its own resx file being used by another web user control (See ...

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

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

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

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

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

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 mfhossain@gmail.com Muhmmad Fakhrul HossainEmail: mfhossain@gmail.comPhone: +88 01715 111512Web: http://www.mfhossain.info 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 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...

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

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

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 asp.net dropdownlist. I created a public event (listchanged) within this user control that I raise when the selectedindexchanged event of the asp.net 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...

Web resources about - want to call one c#.net function in one user control from another user control - asp.net.web-forms

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

Fatally weak MD5 function torpedoes crypto protections in HTTPS and IPSEC
... US Navy ) If you thought MD5 was banished from HTTPS encryption, you'd be wrong. It turns out the fatally weak cryptographic hash function, ...

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

Learning F# – The Thunderdome Principle for Functions
... One object enters, one object leaves! What I like about F# is that the language designers took a similar approach when they implemented functions. ...

HPE Offers Catalog of Virtual Network Functions for Telcos
The vendor's OpenNFV Solution Portal gives carriers a single place to find a range of VNFs that are pre-tested to run on their networks.

7 Useful Technical SEO Functions For Your E-commerce Website
This article was co-authored by Mate Dyekiss, SEO Strategist at IMI. An e-commerce website can create all the technical SEO issues onecan imagine: ...

Using AWS Lambda functions to create print ready files
... going to tell you about our processing architecture as well as at a recent performance improvement with the integration of AWS Lambda functions. ...

Political row over omitting Kerala CM from PM Modi’s function
Kerala chief minister Oommen Chandy on Saturday decided to keep away from Prime Minister Narendra Modi’s function in Kollam in south Kerala after ...

Surprise: Binge-Watching TV May Cause a Decline in Brain Function
With the second season of Transparent only a few days away, some bad news awaits us: According to a recent study and common sense, probably, ...

Power Through Your Work With a “Forcing Function”
... to flow faster and more easily when I know I only have a couple of hours to turn it in. Entrepreneur Dan Martell calls this a “forcing function” ...

Resources last updated: 1/17/2016 10:02:36 PM