locked
Master Page button click calls a subroutine from Child page RRS feed

  • Question

  • User-47461065 posted

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

    Wednesday, January 2, 2013 6:12 AM

Answers

  • User-47461065 posted

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

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 14, 2013 11:54 PM

All replies

  • User-451195045 posted

    Make a class ,use app_code so that your display() metod would available to all pages.....

    Wednesday, January 2, 2013 6:16 AM
  • User-1247037355 posted

    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:

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

    Wednesday, January 2, 2013 6:20 AM
  • User-47461065 posted

    Can you please provide any sample code?

    Wednesday, January 2, 2013 7:52 AM
  • User-1247037355 posted

    Priya621

    Can you please provide any sample code?

    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

    <%@ MasterType VirtualPath="~/masters/SourcePage.master"" %>
     

    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

    Wednesday, January 2, 2013 7:58 AM
  • User-47461065 posted

    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 ?

    Wednesday, January 2, 2013 8:52 AM
  • User260886948 posted

    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

     

    Monday, January 7, 2013 9:54 PM
  • User-47461065 posted

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

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, February 14, 2013 11:54 PM