By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,078 Members | 2,159 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,078 IT Pros & Developers. It's quick & easy.

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

P: n/a
Can it be done?

( This is a related issue to my recent post...
http://groups.google.com/group/micro...0614ae257ae699
...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 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Apr 3, 5:52*pm, DevNll2...@gmail.com 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 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.