Split up default.aspx
I have dynamic page which hides and shows a lot of stuff, div's, depending of what the user is clicking. It works great however the default.aspx gets a bit messy with all that html so I wounder if it is possible to split up the html into smaller parts and still keeping the structure of th开发者_JAVA百科e page?
Thanks M
Yes, split up sub-sections of your code into System.Web.UI.UserControl
s (.ascx). You have to register a tag for your control with Default.aspx, and then you can include it just like you include <asp:
controls.
MyControl.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="MyControl.ascx.cs" Inherits="MyControl" %>
<asp:Label ID="lblCoolLabel" runat="server" />
MyControl.ascx.cs:
public partial class MyControl : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
}
Default.aspx:
<!-- Registers your control -->
<%@ Register TagPrefix="controls" TagName="MyControl" Src="~/controls/MyControl.ascx" %>
<!-- Renders your control -->
<controls:MyControl ID="ucMyControl" runat="server" />
精彩评论