Reputation: 13
I am working on ASP.NET Web form application. I am designing page which contains alot of html elements. I want to separate these elements and make partial pages and then include them in one page for code readability and easy maintenance. I can do this in razor but I could not find any tutorial on this for web form.
Can anybody help?
Upvotes: 1
Views: 1554
Reputation: 21406
For Web Form
, you can create user control
to create a partial page.
You can read about them at this MSDN URL: ASP.Net User Controls
A user control is always named so it ends with ascx
like EditProduct.ascx
or Registeration.ascx
. If you want to use them in a Web Form aspx page
then you can simply drag-n-drop the user control from Solution Explorer
in Visual Studio IDE
. And yes, user controls promote re-use and easier maintenance.
Upvotes: 0
Reputation: 2123
Use UserControl Tutorial on UserControl. They are files with .ascx extension and you can include them in your pages
//UserControl1.ascx
<% @ Control Language="C#" ClassName="UserControl1" %>
<div>
My Custom Control: I can use any Server controls, html tags etc
</div>
Include it in your .aspx page
<%@ Page Language="C#" %>
<%@ Register TagPrefix="uc" TagName="MyCustomControl" Src="~/Controls/UserControl1.ascx" %>
<html>
<body>
<form runat="server">
<uc:MyCustomControl id="MyPartialView"
runat="server" />
</form>
</body>
For more details look here:
Upvotes: 1