ASP NET Custom Control with PersistenceMode.InnerProperty including Server Controls

Controls Server including PersistenceMode.InnerProperty with Control Custom NET ASP

If we want to use a Custom Control with PersistenceMode.InnerProperty. And would like to include some Asp Server Controls we do following:

We create a aspx where the controls to be added:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default9.aspx.cs" 
Inherits="Default9" %>

<%@ Register src="WebUserControl.ascx" tagname="WebUserControl" 
tagprefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
    <uc1:WebUserControl ID="WebUserControl1" runat="server" >
            <asp:Literal ID="lita" Text="Halo" runat="server">
            </asp:Literal><br />
            <asp:LinkButton ID="vdsvs" Text="link" runat="server">
        <SecondLevelInnerString>Hallo vom</SecondLevelInnerString>


After that create a usercontrol where yout put the following markup:


<%@ Control Language="C#" AutoEventWireup="true" 
CodeFile="WebUserControl.ascx.cs" Inherits="WebUserControl" %>
<asp:PlaceHolder ID="Title" runat="server"></asp:PlaceHolder>
<asp:Literal id="litSecondLevelInnerString" runat="server"></asp:Literal>




public partial class WebUserControl : System.Web.UI.UserControl
    private ITemplate _title;

    public ITemplate FirstLevelInnerString
        get { return _title; }
        set { _title = value; }

    public string SecondLevelInnerString
            this.litSecondLevelInnerString.Text = value + 
                " SecondLevelInnerString";

    protected void Page_Load(object sender, EventArgs e)


    protected override void OnInit(EventArgs e)
        if (_title != null)

Thats it!

Now you can use Server Contols in PersistenceMode.InnerProperty Mode.

Comments are closed