473,508 Members | 2,343 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple c# question on master page functions

4 New Member
Hi,

I'm trying to do something that should seem very simple. I want to include a function in a master page that I can call in all of it's child pages. Something like this:

master page code:

void helloWorld()
{ response.write("Hello World");}


child page code:

<% page.master.helloWord() %>

I am fairly new to asp.net and have very little programming experience with c#, so pardon me if this is a dumb question. If you know the answer, PLEASE respond with the actual code to do the above.

Thanks in advance!
Nov 29 '07 #1
1 1033
aaronsandoval
13 New Member
If you are wanting to call a method from a "Master Page's Code Behind Page" then you will have to declare the following in the HTML side of your ASPX page.

Expand|Select|Wrap|Line Numbers
  1. <%@ MasterType VirtualPath="~/MasterPage1.master" %>
  2.  
So an example of the HTML page would be:
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" MasterPageFile="~/MasterPage1.master" AutoEventWireup="true" CodeFile="DefaultWMP1.aspx.cs" Inherits="DefaultWMP1" Title="Default With Master Page 1" %>
  2.  
  3. <%@ MasterType VirtualPath="~/MasterPage1.master" %>
  4.  
  5. <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
  6. </asp:Content>
  7.  

Then your ASPX Code Behind Page method would be:
Expand|Select|Wrap|Line Numbers
  1. public partial class DefaultWMP1 : System.Web.UI.Page
  2. {
  3. protected void Page_Load(object sender, EventArgs e)
  4. {
  5. Master.HelloWorld();
  6. }
  7. }
  8.  
Hope this helps...

- Aaron Sandoval
"remember: Greatness can easily be achieved, as long as you never stop wanting to learn from others..."
Nov 29 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

20
2395
by: Alan Silver | last post by:
Hello, In classic ASP, I used to use two include files on each page, one before and one after the main content, to provide a consistent layout across a web site. That way I could just change the...
1
1451
by: Alan Silver | last post by:
Hello, I am just converting some pages to use master pages, and I have come across a bit of a problem. One of the pages uses some custom Javascript functions for client-side validation. Now,...
5
1448
by: Support | last post by:
Hello: I have the following code that currently needs to go in every page. QUESTION 1) Can Page_Preinit go somewhere else more global like Global.asax so that I dont have to copy this code in...
3
2273
by: Mark Olbert | last post by:
I have some img tags on a master page which reference files in a top-level directory. They look like this: <img src="assets/test.gif" id="gnr" /> assets is a subdirectory of the website root. ...
0
894
by: RAM | last post by:
Hello, I have created simple ASP.NET application with master page MIMStock.master: <%@ Master Language="C#" AutoEventWireup="true" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0...
1
1748
by: Don | last post by:
I'm using master pages and have added some base functionality (public functions) into this class. I then create a new web form using the above as the master page. In the code of my new web form,...
2
4210
by: Sasquatch | last post by:
I'm having trouble creating a simple login page using the asp:login control. I followed some instructions in a WROX book, "Beginning ASP.NET 2.0," and the instructions are very straight forward,...
13
5291
by: Kirk | last post by:
I have been reading Scott Allen's article on Master Pages (http:// odetocode.com/Articles/450.aspx) but I am having problems understanding a concept. Specifically, I have created a property...
10
2106
by: =?Utf-8?B?RGFuaQ==?= | last post by:
Hi, Trying to create a master page that holds a menu, and the menu switches between pages in the site. 2 problem arrosed: a. When I navigate from page to page (all AJAX Web Forms, with the...
0
7225
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7324
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
7042
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7495
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
3193
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3181
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1556
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
766
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
418
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.