944,164 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Marked Solved
  • Views: 885
  • ASP.NET RSS
Oct 25th, 2009
0

Execute MastePage event from a content webform

Expand Post »
Hi, I would like to know how can I execute an event from a web content form, for example i would like to run a centralized event to assign rigths to component in every webform, but i would like to do that from the master page so i do not have to redo the same code in all web form load event.

Thanks for any help you can provide me. VS2008
Similar Threads
Reputation Points: 56
Solved Threads: 56
Posting Pro in Training
jbisono is offline Offline
433 posts
since May 2009
Oct 26th, 2009
0
Re: Execute MastePage event from a content webform
Each child web forms will have different controls. If you want to access child page controls in your master page, then you can do it something like
ASP.NET Syntax (Toggle Plain Text)
  1. ContentPlaceHolder1.FindControl("Button1")

Or do you want to get master page event in your child pages? if so, refer this link.
Last edited by Ramesh S; Oct 26th, 2009 at 3:43 am.
Reputation Points: 165
Solved Threads: 113
Posting Pro
Ramesh S is offline Offline
580 posts
since Jun 2009
Oct 26th, 2009
0
Re: Execute MastePage event from a content webform
Actually is something like the link you provide here, but i do not have any button to trigger this code it just run in the load page, well the thing is that piece of code is general for every single webform i have, but then maybe i would like to add some code to the specific webform. I hope you know what im saying.
Reputation Points: 56
Solved Threads: 56
Posting Pro in Training
jbisono is offline Offline
433 posts
since May 2009
Oct 26th, 2009
0
Re: Execute MastePage event from a content webform
Hi jbisono ,

I am clear about your requirement now. You may need to write code specific to the child pages in the page _load event of the master page. So that it will be executed automatically for all child pages.

You can use Page.GetType().Name or other technique like this to get the child page name in Master page and write the specifc code to it.

Alternatively you can create BasePage class and inherit all your child pages from this class.Override the OnLoad event in the BasePage and write code specific to the pages inherited from it.
Last edited by Ramesh S; Oct 26th, 2009 at 9:49 am.
Reputation Points: 165
Solved Threads: 113
Posting Pro
Ramesh S is offline Offline
580 posts
since Jun 2009
Oct 26th, 2009
0
Re: Execute MastePage event from a content webform
Ok, Thanks Ramesh, Actually with your previous comment i got it to do what i want, but the master page load event trigger after the content load event which i would like to run the content load event after the master page. if that possible?.
Reputation Points: 56
Solved Threads: 56
Posting Pro in Training
jbisono is offline Offline
433 posts
since May 2009
Oct 26th, 2009
0
Re: Execute MastePage event from a content webform
Ok, Ramesh I think i got it, I use the link you provide to use the preinit but insted of using preinit i use prerender in that case i can execute my code from the master page in the load event in then the prerender in the content page to whatever i want in my content form. what do you think is that a good practice?.

Oh and thank you for your help.
Reputation Points: 56
Solved Threads: 56
Posting Pro in Training
jbisono is offline Offline
433 posts
since May 2009
Oct 27th, 2009
1
Re: Execute MastePage event from a content webform
Hi jbisono,

The values of the controls will not be loaded from ViewState in PreInit event. Therefore avoid to use it.

Since it seems that you want to execute some code in master page and then some code in child pages, what you mentioned is a good idea.
Last edited by Ramesh S; Oct 27th, 2009 at 2:01 am.
Reputation Points: 165
Solved Threads: 113
Posting Pro
Ramesh S is offline Offline
580 posts
since Jun 2009
Oct 27th, 2009
0
Re: Execute MastePage event from a content webform
Yes, well for now im going to mark this thread as solved once the program is doing what i want, thank your very much for your help if i have another issue i will be around thanks again.

regards.
Reputation Points: 56
Solved Threads: 56
Posting Pro in Training
jbisono is offline Offline
433 posts
since May 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: How to maintain scroll position.
Next Thread in ASP.NET Forum Timeline: Need to be able to move rows in GridView or something similar





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC