Asp.net 2.0

Mahesh Dahale

Mahesh Dahale

@mahesh-E2tZ3t • Oct 22, 2024

ASP.NET 2.0 - Master Pages
It provide templates for other pages on your web site. with shared layout and functionality.

allow you to create a consistent look and behavior for all the pages

It defines placeholders for the content, which can be overridden by content pages. The output result is a combination of the master page and the content page.

The content pages contains the content you want to display.

When users request the content page, ASP.NET merges the pages to produce output that combines the layout of the master page with the content of the content page.

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
   
  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
   
  <html xmlns="https://www.w3.org/1999/xhtml">
  <head id="Head1" runat="server">
      <title>Untitled Page</title>
      <asp:ContentPlaceHolder id="head" runat="server">
      </asp:ContentPlaceHolder>
  

The @ Master directive defines it as a master page.

The master page contains a placeholder tag <asp:ContentPlaceHolder> for individual content.
The id="Head1" attribute identifies the placeholder, allowing many placeholders in the same master page.

Replies

Welcome, guest

Join CrazyEngineers to reply, ask questions, and participate in conversations.

CrazyEngineers powered by Jatra Community Platform

  • Mahesh Dahale

    Mahesh Dahale

    @mahesh-E2tZ3t Nov 9, 2009

    .NET controls can be inserted into the other content page just like an into an ordinary page.

        <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="AboutUs.aspx.cs" Inherits="About_Us" Title="Untitled Page" %>
       
      <asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
      </asp:Content>
      <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder2" Runat="Server">
          
          
             <h3>About PIS</h3> 
          
          <p>
      </asp:Content>
      
  • sarveshgupta

    sarveshgupta

    @sarveshgupta-txtmu5 Nov 10, 2009

    Master Pages are really helpful in cases when you have a standard frame or backdrop layout for your site that has to repeated on every page of that site.

    Create that once using a master page and use it on any number of pages as you want easily by refering to it as shown in the second code.

  • Mahesh Dahale

    Mahesh Dahale

    @mahesh-E2tZ3t Nov 10, 2009

    The Page.IsPostBack Property
    It runs EVERY time the page is loaded
    you can use the Page.IsPostBack property.
    If you want to execute the code in the Page_Load subroutine only the FIRST time the page is loaded
    If the Page.IsPostBack property is false, the page is loaded for the first time, if it is true, the page is posted back to the server

    [COLOR=blue]Sub[/COLOR] Page_Load
        [COLOR=blue]If[/COLOR] [COLOR=blue]Not[/COLOR] IsPostBack
                     Validate()
        [COLOR=blue]End[/COLOR] [COLOR=blue]If[/COLOR]
    [COLOR=blue]End[/COLOR] [COLOR=blue]Sub[/COLOR]
    
    [COLOR=blue]private[/COLOR] [COLOR=blue]void[/COLOR] Page_Load()
    {
        [COLOR=blue]if[/COLOR] (!IsPostBack)
        {
            Validate();
        }
    }
    
  • sarveshgupta

    sarveshgupta

    @sarveshgupta-txtmu5 Nov 11, 2009

    Yes, IsPostBack helps to check that if the user has visited for the first time that is if it is a completely new session or the user is moving on the site or refreshing the page

  • Gurjeet Singh

    Gurjeet Singh

    @gurjeet-LUX7B1 Nov 11, 2009

    what is the use of Autoeventwireup written in the first line of c sharp code.and by default it is true. ?

  • sarveshgupta

    sarveshgupta

    @sarveshgupta-txtmu5 Nov 11, 2009

    The ASP.NET page framework supports an automatic way to associate page events and methods.

    If the AutoEventWireup attribute of the Page directive is set to true (or if it is missing, since by default it is true), the page framework calls page events automatically, specifically the Page_Init and Page_Load methods. In that case, no explicit Handles clause or delegate is needed.

    But, in Visual Studio, if it is true, then the names of the methods must be as specified in its library otherwise it will not match and the events and methods will not be called.
    As a consequence, you should always leave AutoEventWireup set to false when working in Visual Studio.

  • Mahesh Dahale

    Mahesh Dahale

    @mahesh-E2tZ3t Nov 11, 2009

    cooldudeietwhat is the use of Autoeventwireup written in the first line of c sharp code.and by default it is true. ?

    The ASP.NET page framework also supports an automatic way to associate page events and methods.

    The default value for AutoEventWireup is true for a C# web form, and false for a VB.NET web form.

    When AutoEventWireup is true,
    The ASP.NET runtime will automatically find and fire the method for the appropriate event. such as Page_Load() etc.
    (the ASP.NET page framework can automatically raise events.)

    If we switch to AutoEventWireup= false for a C# web form,
    there is a little extra work to do. Somewhere we need to
    explicitly wire up events.
    (you must manually hook up events to event handlers)

  • Gurjeet Singh

    Gurjeet Singh

    @gurjeet-LUX7B1 Nov 11, 2009

    Thanks @mahesh,@sarvesh 😀