views:

26

answers:

2

Hi, 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 the page?

Thanks M

+1  A: 

Yes, split up sub-sections of your code into System.Web.UI.UserControls (.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" />
Alex
AKA Web User Controls
Brad
Thanks, this was exactly what I was looking for!
Mikael
A: 

Try using UserControls. They will make your life simpler :)