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't afford this solution.

 Is there a workaround for this, any help would be greatly appreciated.

 Thanks

Ponnu


Thanks
Ponnu
0
Ponnu
9/9/2006 9:20:16 PM
asp.net.web-forms 93655 articles. 5 followers. Follow

8 Replies
1444 Views

Similar Articles

[PageSpeed] 54

Create an empty user control and use that one to define all your general functions in the code behind.
On every page/usercontrol where you need to call a general function (like GetEmployeeSomething()) you include this usercontrol. Since it is an empty usercontrol (design wise) you won't see it in your page, but you can call the functions in the code behind without any problems. This way you will have all your functions together in one user control, which makes it easier to do adjustments and keeping a good overview of all general functions.

Get this example: all general functions go into a user control called "user_functions.acx".
If you have a page "myPage.aspx" where you need to call general functionA, you include user_functions.ascx on this page.
If myPage.aspx also uses a user control "myUserControl.ascx", and in myUserControl.ascx you need to call general functionB then you'll need to include user_functions.ascx in myUserControl.ascx as well even if you already included it in myPage.aspx. In a standard setup you cannot call functionB from myUserControl.ascx even if user_functions is included in myPage.aspx. You'll need to include it in every page, every user control where you need the general functions.

I hope this clears up a few things :)

0
Speerman
9/11/2006 8:45:21 AM

Hi Speerman,

 I just gave an exmaple like GetEmployeeSomething() but this is not a generic function. I actually do a set of operations like hiding\showing something, registering script tags ..etc. which are specific to the user control.

 so I used to give wucCompany.wucEmployee.GetEmployeeSomething() in ASP.Net 1.1, here GetEmployeeSomething()(should be actually setEmloyeeLayout()) is an exampe which hides\shows objects, registers tags that are specific to wucEmployee.

In ASP.Net 2.0, I am unable to call the function like wucCompany.wucEmployee.GetEmployeeSomething(), instead I am calling like wucCompany.GetEmployeeSomething(). The GetEmployeeSomething() of wucCompany inturn calls the GetEmployeeSomething() of wucEmployee. I need to do this change in lot of usercontrols and can't afford this soluion.

 I hope you get the idea of what my problem is

Thanks

Ponnu


Thanks
Ponnu
0
Ponnu
9/11/2006 9:13:06 AM

So you have a usercontrol called "wucCompany" which includes another usercontrol called "wucEmployee" ?
You have a page wich uses the usercontrol wucCompany and on this page you want to call the function "GetEmployeeSomething" (which is a function of wucEmployee) ?

Just making sure I get the actual setup of the problem :)

0
Speerman
9/11/2006 9:18:57 AM

Hi Speerman,

 you are right, that's my problem.

I am unable to call wucCompany.wucEmployee.GetEmployeeSomething() in ASP.Net 2.0.

 Thanks

Ponnu


Thanks
Ponnu
0
Ponnu
9/11/2006 9:27:46 AM

What you say is true, you can't access the wucEmployee through wucCompany because it's a private object for wucCompany.

I think it's a design issue, if you need the access the wucEmployee from the aspx page you need to include the wucEmployee control in your aspx page and not in the wucCompany user control (unless you need it there too).

Only way to solve it is either include it in the aspx page or doing what you already did, creating a pass through function in wucCompany to access the wucEmployee function.

0
Speerman
9/11/2006 2:02:04 PM

Hi Speerman,

 Thanks for the suggestion.

I could not use wucEmployee in aspx page. So I have to do it by creating a pass through function and call that.

 what I don't understand is it used to work in ASP.Net 1.1 and why it doesn't work the same way in ASP.Net 2.0. The function in the innermost wuc wucEmployee is public, then why can't I just access it.

I am able to acess wucCompany.wucEmployee from the aspx page, it's just I am not able access any user defined public functions\properties of wucEmployee. I am able to access wucCompany.wucEmployee.ClientID from aspx page and not any user defined functions/properties.

Could you please provide me some light on this.

 Thanks

Ponnu


Thanks
Ponnu
0
Ponnu
9/11/2006 2:40:12 PM

Hmm when I tried the same setup here I couldn't even get to wucEmployee from the aspx page.

I don't know exactly why you can see wucEmployee but can't access methods. It's some security thing but I don't know why exactly from the info I have.

0
Speerman
9/11/2006 3:27:40 PM

Hi Speerman,

 Thanks for the Info.

Ponnu.


Thanks
Ponnu
0
Ponnu
9/11/2006 4:33:44 PM
Reply:

Similar Artilces:

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

Accessing a user control's div tag from another user control
Hi,I have a form that has two placeholders- a primary and a secondary, for two different usercontrols. At runtime I unload one user control from the primary placeholder and load the second user control onto the secondary placeholder. Before doing the unloading and loading, I need to fill the innerhtml of a div tag in the second user control(the one I am going to load) from the first one(the one I am going to unload). I have been able to get a reference to the second usercontrol but dont know what to do next. Please advise. Your help is appreciated. Suppose you have two user ...

Accessing a control's properties in another user control?
I have two user controls on the page, control A and control B. Control B has a bunch of panels in it that I need to access from Control A. Control A needs to lookup a panel in Control B and turn its visibility on or off based on some criteria. Using the FindControl() method how can I accomplish this? I have no problem accessing a control from the Page or from within the same control, but I haven't figured out how to access the properties of a different control than the one thats requesting the info. Thanks. You *could* do a FindControl on the Parent of UserControl A, to get a reference t...

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

Label control's text doesn't appear to be set (in the page which has a user control )when trying to update the text property in the FormView's ItemUpdated event
Hi There,I have a user control which hosts a formview control, gridview control and a label control. The grid view is usedto show rows in the DB and when clicked to edit each row, a form view opens up in edit mode with that particular row info. So I have nothing in the item template.My first question is..is it mandatory to have smth in the itemtemplate of the form view.I have controls in edititemtemplate and insertitemtemplate.When a particular row is edited, I would like to show a status msg showing that the row has been updated.For this, I use the ItemUpdated event of the formview and try ...

Accessing Parent's control form User Control?
Hi, I have a Webform and a User Control in it. The form has a panel and textbox in it. The User control has a button in it. Using that Button, I want to show/hide the panel. But, my issue is how to get access to Parent's controls (in this case, the parent control is Panel). Please advice. Thanks in advance. Easy... just make the controls you want to access in the Page public and then cast the Page in the control to the appropriate type and access the now public controls.... uhh??? got that ;-) Example: Page: Name MyPage Controls in MyPage: public System.Web.UI.WebCo...

Can I hide a user control's control from the hosting page's client script?
Okay, my previous question was not unswered and I guess you can't hide a control's panel with server code then show it with client code. Now this is what I try to do: on the hosting page's onload event, call a function to hide the user control's penal. Here is the deal: the user control was looped as many times as data required. So the penals will be name mypanel1, my panel2, etc... that is not even a problem if I know if the following is true: * Do all server codes finish running before the page get sent back to the client? Say the database gave me 5 penals, I can then determine how...

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 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 a user-control's properties from within another
Hi everybody. I have a page with two user-controls. Upon clicking a button in one of my controls i want to change some properties of the other user control. Let's say i call one control "tasks" and the other "loginarea". This is the event handler for the button in the "tasks" control: void foo(Object Sender, EventArgs e) { loginarea.spanmessage="You must log in"; } Of course this doesn't work... Can you help me? What do you mean that this does not work? Syntax error, run-time error, logical error? And what control is the &q...

Access parent page's controls from a user control
I have a .ascx user control that contains a button. I place this user control on a .aspx web page. The web page contains a textbox. When I click on the button in the user control I want the data in the textbox (in the web page) to be saved to the database. I want to write this code in the click event of the user control's button. Is there any way I can access the parent web page's controls from the user control? Add event to user control which fires on page when button inside user control is clicked. view post 779045Jigar Desai-----------------------Do not forget to "Mark as Answer...

Getting a web form's properties to a Custom User Control
Ok. This is hopefully a simple question that someone could help me out on. I've researched but only found out how to get a user control properties to a web form. Problem:  Anyway, I have created a custom user control (Help button with a menu extender) which will be used on several pages. The menu that extends from the button will not be static, so I will want to load the right data (from my xml file) depending on which page the help button is on. For example, my custom user control will be on pages news and the other on media. Now, when the user control loads on the news page, I need ...

User control can't access the parent page's public properties
Hi Guys I have built a page that is contained within a master page and it holds 2 user controls Control A contains a DataListControl B contains a FormView I want to pass the selected index from the DataList on Control A to the FormView on Control B so it acts like a master / detail scenario I created a public property on the page that contains both controls called DataListSelectedIndex A also created a public property for DataListSelectedIndex on the Control  I populate the DataListSelectedIndex property of the Control when the DataList_SelectedIndexChanged...

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

Web resources about - Unable to access user control's user control's function\property from another user control - asp.net.web-forms

Resources last updated: 12/3/2015 7:38:26 PM