usercontrol get access to masterpage
-
I have an aspx page(X) that uses a masterpage(Y). The page(X) uses a usercontrol. I want to get access to the masterpageclass(Y) from the usercontrol. The reason for this is that I have some functionallity for errormessage alerts in my masterpage that I want to use from my usercontrol when something goes wrong. How can I do this? I know that I get the masterpage with this.parent.page.master but then I have to parse that into my masterpageclass but I can't access my masterpageclass. If I don't parse it I don't get access to the functions in the masterpage. Thanx!
-
I have an aspx page(X) that uses a masterpage(Y). The page(X) uses a usercontrol. I want to get access to the masterpageclass(Y) from the usercontrol. The reason for this is that I have some functionallity for errormessage alerts in my masterpage that I want to use from my usercontrol when something goes wrong. How can I do this? I know that I get the masterpage with this.parent.page.master but then I have to parse that into my masterpageclass but I can't access my masterpageclass. If I don't parse it I don't get access to the functions in the masterpage. Thanx!
Hi there, Your user control may not need to directly access the Master Page to use some utility functions in there. Instead, your content page which contains the user control will do that, here you can consider using the event/delegate pattern. By this I mean, you can define a custom event in the user control, and the content page will hook this event. Every time your user control wants to display error message, it simply raises the custom event to notify the content page which in turn calls the functions in the Master Page.
-
Hi there, Your user control may not need to directly access the Master Page to use some utility functions in there. Instead, your content page which contains the user control will do that, here you can consider using the event/delegate pattern. By this I mean, you can define a custom event in the user control, and the content page will hook this event. Every time your user control wants to display error message, it simply raises the custom event to notify the content page which in turn calls the functions in the Master Page.
-
minhpc_bk wrote:
that, here you can consider using the event/delegate pattern.
Wow min that the best advice I've seen given on this forum in a long, long, time. :-> 1 line of code equals many bugs. So don't write any!!