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.
⭐ 6 followers.

💬 8 Replies
👁️‍🗨️ 2110 Views

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: