I want to build a user control suppose MyDiv.ascx. This control renders the div tag and do few more code behind stuff like adding few attributes etc which is not a matter of
I also wanted to create a custom control with "innerHtml". This is what I ended up with (based partially on some of the earlier answers/comments)...
div.ascx.cs:
[ParseChildren(true, "Text")] //Store inner content in Text property
public partial class div : System.Web.UI.UserControl
{
public string Text { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
litText.Text = Text; //Render it however you want
}
}
div.ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="div.ascx.cs" Inherits="TestApp.Controls.div" %>
Test page:
<%@ register src="~/Controls/div.ascx" tagname="div" tagprefix="uc" %>
Test data