The following codes are simplified.
The user-control ascx:
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="BaseFormControl.ascx.cs"
Inherits="SOPR.CustomForms.BaseFormControl" %>
<fieldset class="fset1">
</fieldset>
This is my user control code-behind:
public partial class BaseFormControl : System.Web.UI.UserControl
{
[TemplateContainer(typeof(ContentContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate Content { get; set; }
void Page_Init()
{
if (Content != null)
{
ContentContainer cc = new ContentContainer();
Content.InstantiateIn(cc);
contentHolder.Controls.Add(cc);
}
}
My usage in the view:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddOperator.aspx.cs"
Inherits="SOPR.Cadastro.AddOperator" MasterPageFile="~/MasterPage.Master" %>
<asp:Content ContentPlaceHolderID="ContentPlaceHolder1" ID="maincont" runat="server" EnableViewState="true">
<uc:BaseFormControl ID="BaseFormControl1" runat="server">
<Content>
<asp:TextBox runat="server" CssClass="keytbcss" MaxLength="4" ID="keytb"
NewLine="false" />
</Content>
</uc:BaseFormControl>
I'm trying to access the "keytb" control on the code-behind, but its like it didnt exist (like using a variable that doesn't exist). Any ideas?
Thanks in advance.
SOLUTION --------------------------
I found a quite nice solution, just add [TemplateInstance(TemplateInstance.Single)] to the ITemplate property of the user control and everything gets seen. I can now use just like it was a normal page control.
public partial class BaseFormControl : System.Web.UI.UserControl
{
[TemplateContainer(typeof(ContentContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateInstance(TemplateInstance.Single)]
public ITemplate Content { get; set; }
...
SOLUTION --------------------------
I found a quite nice solution, just add [TemplateInstance(TemplateInstance.Single)] to the ITemplate property of the user control and everything gets seen. I can now use just like it was a normal page control.
public partial class BaseFormControl : System.Web.UI.UserControl
{
[TemplateContainer(typeof(ContentContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
[TemplateInstance(TemplateInstance.Single)]
public ITemplate Content { get; set; }
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With