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

Asked

Viewed 28 times

1

I am maintaining an old application that uses Web Forms. This application uses Iframe to make a kind of layout reuse.

The problem is that even doing this, a lot of code is repeating, and I’d like a solution to that.

I come from PHP and Python, where 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?

  • In Webforms you can use Materpage... but it does not match your Iframe scenario, because it isolates the content inside it and will not reuse anything...

  • @Leandroangelo is the Masterpage. Put the answer there :D

  • managed to hit his master?

1 answer

1

What you are looking for is called Masterpage, in it are the components and visual elements that are shared by all pages of your application Webforms, below is 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 should declare it as such.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.