J
Jason
I am trying to dynamically add a web user control - ctrlBlogEntry.ascx
- to a page - default.aspx - (via an ASP
laceHolder). This web user
control has two ASP:Label controls and I'm accessing their "Text"
properties via public properties. However, after I have instantiated
the ctrlBlogEntry control in the PageLoad method of default.aspx, it is
failing when I try to set the text of the label controls in the
ctrlBlogEntry control. Here is some code:
There is probably a very simple, obvious fix for this, I just can't
seem to see it. Can someone help?
default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="be" TagName="ctrlBlogEntry"
Src="/blog/controls/ctrlBlogEntry.ascx" %>
<be:ctrlBlogEntry id="ctrlBE" BlogTitle="Test" runat="server" />
<!--This one works just fine-->
<asp
laceholder id="phBlogEntries" runat="server" />
default.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
controls_ctrlBlogEntry ctrlBE = new controls_ctrlBlogEntry();
ctrlBE.BlogTitle = "Test Title"; //Fails here.....
ctrlBE.BlogBody = "Test Body";
phBlogEntries.Controls.Add(ctrlBE);
}
ctrlBlogEntry.ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="ctrlBlogEntry.ascx.cs" Inherits="controls_ctrlBlogEntry" %>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="tableHeader">
<asp:Label ID="lblTitle" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblBody" runat="server" />
</td>
</tr>
</table>
ctrlBlogEntry.ascx.cs:
public partial class controls_ctrlBlogEntry : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string BlogTitle
{
set
{
lblTitle.Text = value;
}
}
public string BlogBody
{
set
{
lblBody.Text = value;
}
}
}
- to a page - default.aspx - (via an ASP
control has two ASP:Label controls and I'm accessing their "Text"
properties via public properties. However, after I have instantiated
the ctrlBlogEntry control in the PageLoad method of default.aspx, it is
failing when I try to set the text of the label controls in the
ctrlBlogEntry control. Here is some code:
There is probably a very simple, obvious fix for this, I just can't
seem to see it. Can someone help?
default.aspx:
<%@ Page Language="C#" AutoEventWireup="true"
CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register TagPrefix="be" TagName="ctrlBlogEntry"
Src="/blog/controls/ctrlBlogEntry.ascx" %>
<be:ctrlBlogEntry id="ctrlBE" BlogTitle="Test" runat="server" />
<!--This one works just fine-->
<asp
default.aspx.cs:
protected void Page_Load(object sender, EventArgs e)
{
controls_ctrlBlogEntry ctrlBE = new controls_ctrlBlogEntry();
ctrlBE.BlogTitle = "Test Title"; //Fails here.....
ctrlBE.BlogBody = "Test Body";
phBlogEntries.Controls.Add(ctrlBE);
}
ctrlBlogEntry.ascx:
<%@ Control Language="C#" AutoEventWireup="true"
CodeFile="ctrlBlogEntry.ascx.cs" Inherits="controls_ctrlBlogEntry" %>
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="tableHeader">
<asp:Label ID="lblTitle" runat="server" />
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblBody" runat="server" />
</td>
</tr>
</table>
ctrlBlogEntry.ascx.cs:
public partial class controls_ctrlBlogEntry : System.Web.UI.UserControl
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string BlogTitle
{
set
{
lblTitle.Text = value;
}
}
public string BlogBody
{
set
{
lblBody.Text = value;
}
}
}