Create a base class for your pages (e.g. BasePage) and then inherit your pages from that class. Then create a virtual method in your base class and override it in your page classes. You can then call that virtual method from the master page:
(cphContent.Page as BasePage ).CustomMethod();
cphContent is the ID of the ContentPlaceHolder in your master page.
Make sure that the content page you're referring to in the master page is not null.
For the GridView, input values are taken from masterpage components.
I am having a subroutine in the childpage which is called in button_Click of the childpage. That subroutine I want to call in MasterPage's button_Click. Is it possible ?
Generally speaking, it is possbile.
For example, as the subroutine is a small function, then it can call the button_click of the childpage and call MasterPage's button_Click, and get some value from the master page.
But I do not know the exact relationship between those masterpage components, button click and the subroutine, I do not know if it has some data conflict when call those function.
Please just have a try, if you meet any problem, please let me know.
Best Regards,
Amy Peng
Please mark the replies as answers if they help or unmark if not.
Feedback to us
Priya621
Member
8 Points
31 Posts
Master Page button click calls a subroutine from Child page
Jan 02, 2013 10:12 AM|LINK
I am having a Button in Master Page.
Child page is having a subroutine with the name display().
I need to call the display() sub in MasterPage's Button Click.
please help me!!!
Its urgent!!!
shivalthakur
Participant
1837 Points
531 Posts
Re: Master Page button click calls a subroutine from Child page
Jan 02, 2013 10:16 AM|LINK
Make a class ,use app_code so that your display() metod would available to all pages.....
Response.Write("Success");
Best Of Luck
Shival Thakur
ramramesh
Member
458 Points
158 Posts
Re: Master Page button click calls a subroutine from Child page
Jan 02, 2013 10:20 AM|LINK
To call a content page method from master page:
Create a base class for your pages (e.g. BasePage) and then inherit your pages from that class. Then create a virtual method in your base class and override it in your page classes. You can then call that virtual method from the master page:
Make sure that the content page you're referring to in the master page is not null.
Priya621
Member
8 Points
31 Posts
Re: Master Page button click calls a subroutine from Child page
Jan 02, 2013 11:52 AM|LINK
Can you please provide any sample code?
ramramesh
Member
458 Points
158 Posts
Re: Master Page button click calls a subroutine from Child page
Jan 02, 2013 11:58 AM|LINK
In your master page's code behind replace the protected keyword on the event handler to public.
public void LinkButton1_Click(object sender, EventArgs e) { //Do Stuff Here }IN your content page use the Master Type Directive
In the code behind for the content page call the Master event handler as follows
protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { this.Master.LinkButton1_Click(sender, e); }Note the code is C#.
I'm looking into calling the master pages event handler more directly
Priya621
Member
8 Points
31 Posts
Re: Master Page button click calls a subroutine from Child page
Jan 02, 2013 12:52 PM|LINK
Here child page is containing the GridView.
For the GridView, input values are taken from masterpage components.
I am having a subroutine in the childpage which is called in button_Click of the childpage. That subroutine I want to call in MasterPage's button_Click. Is it possible ?
Amy Peng - M...
Star
10123 Points
958 Posts
Microsoft
Re: Master Page button click calls a subroutine from Child page
Jan 08, 2013 01:54 AM|LINK
Hi Priya621,
Generally speaking, it is possbile.
For example, as the subroutine is a small function, then it can call the button_click of the childpage and call MasterPage's button_Click, and get some value from the master page.
But I do not know the exact relationship between those masterpage components, button click and the subroutine, I do not know if it has some data conflict when call those function.
Please just have a try, if you meet any problem, please let me know.
Best Regards,
Amy Peng
Feedback to us
Develop and promote your apps in Windows Store
Priya621
Member
8 Points
31 Posts
Re: Master Page button click calls a subroutine from Child page
Feb 15, 2013 03:54 AM|LINK
Finally I got solution through session variables.
I created session variables in masterpage button click with a page redirecting to childpage and I passed those variables in my subroutine.
Thanks all for helping me!!!