Calling Master Page methods directly from Content Page inline code(.aspx file)

Discussion in 'ASP .Net' started by DevNll2002@gmail.com, Apr 3, 2008.

  1. Guest

    Can it be done?

    ( This is a related issue to my recent post...
    http://groups.google.com/group/micr...read/thread/a229a66642bedfaf/870614ae257ae699
    ...but with a twist. )

    Here's the scenario:

    Method in MyMaster.master.cs:
    public void Logout(object sender, EventArgs e)
    {
    Response.Write("You are logged out!");
    }


    Code in MyContent.aspx:
    <%@ MasterType VirtualPath="~/MyMaster.master" %>
    ...
    <asp:Button ID="btnLogout" runat="server" Text="Logout"
    OnClick="Master.Logout" />


    Browse to the page, and in big red letters:
    Server Application Unavailable


    Application log in Event Viewer shows:
    Event Type: Error
    Event Source: ASP.NET 2.0.50727.0
    Event Category: None
    Event ID: 1000
    Description: aspnet_wp.exe (PID: 3368) stopped unexpectedly.

    This happens every time that 'Master.' is used directly in the .aspx
    code.

    A workaround is to call Master.Logout from within a MyContent.aspx.cs
    method, then reference the latter method in MyContent.aspx.

    MyContent.aspx *is* seeing the method in MyMaster.master.cs, because
    it will throw errors for certain things like leaving out the overloads
    in the Logout method declaration.

    Is there a correct syntax for calling a Master Page method directly
    from inline code, or should it just not be done?

    Thanks.
    , Apr 3, 2008
    #1
    1. Advertising

  2. Guest

    Re: Calling Master Page methods directly from Content Page inlinecode (.aspx file)

    On Apr 3, 5:52 pm, wrote:
    > Can it be done?


    Answer:
    Yes it can!

    The method has to be set in code, though:

    btnLogout.Click += new EventHandler(Master.Logout);
    , Apr 9, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. hazz
    Replies:
    6
    Views:
    49,288
    SkyUCHC
    Jun 9, 2010
  2. Daniel Vallstrom
    Replies:
    2
    Views:
    1,807
    Kevin Bracey
    Nov 21, 2003
  3. Matthew Bell
    Replies:
    8
    Views:
    302
    Peter Hansen
    Oct 29, 2004
  4. Chevron Boyde
    Replies:
    1
    Views:
    1,091
    George
    Dec 8, 2008
  5. SerpentKiss2010
    Replies:
    0
    Views:
    2,453
    SerpentKiss2010
    Apr 6, 2011
Loading...

Share This Page