Is there any way to extend a main file in Webforms?

1

I'm servicing an old application that uses Web Forms. This application uses Iframe to make a kind of layout reuse.

The problem is that while doing this, a lot of code is being repeated, and I would like a solution for that.

I come from PHP and Python, where the frameworks use main layouts, which can be extended by the views used. I have no idea how to do this in Web Forms (or even if it is possible to do this).

Is there any way to use a main layout with ASPX files? How to do this?

    
asked by anonymous 09.03.2018 / 13:13

1 answer

1

What you are looking for is called MasterPage, it contains the components and visual elements that are shared by all the pages of your WebForms application, below an example.

Site.master

<%@ Master Language="C#" AutoEventWireup="true" CodeFile="Site.master.cs" Inherits="Site" %>
 <html>

  <head>
    <asp:ContentPlaceHolder id="head" runat="server">
    </asp:ContentPlaceHolder>
  </head>

  <body>
    <form id="form1" runat="server">
      <div>
        <!-- Aqui vão as suas páginas de conteúdo-->
        <asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">

        </asp:ContentPlaceHolder>
      </div>
    </form>
  </body>
 </html>

Now when creating your content pages that should be presented by this template you must declare it as such.

<%@ Page Language="C#" MasterPageFile="~/Site.master" ... %>
    
10.03.2018 / 21:44