M
Mike Irwin
I'm having a little difficulty with the set accessor. I'm working on a
template-based site design and trying to use the set accessor to set the
document's title. The problem is that it's not setting the title and I
can't seem to figure out what I'm missing. Here's some sample code:
---
ControlBase.cs
---
public class ControlBase : System.Web.UI.UserControl
{
private string _strTitle;
public string Title
{
get
{
return _strTitle;
}
set
{
_strTitle = value;
}
}
}
---
Default.aspx
---
<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false"
Inherits="namespace.PageBase" %>
....
<title><asp:literal id="litTitle" runat="server"></asp:literal></title>
---
Default.aspx.cs
---
public class PageBase : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Literal litTitle;
private ControlBase _ctlContent;
private void Page_PreRender(object sender, System.EventArgs e)
{
if (_ctlContent.Title != string.Empty)
{
this.litTitle.Text = _ctlContent.Title;
}
}
}
---
Default.ascx.cs
---
public class Default : ControlBase
{
private void Page_Load(object sender, System.EventArgs e)
{
this.Title = "This should be the title of the document";
}
}
template-based site design and trying to use the set accessor to set the
document's title. The problem is that it's not setting the title and I
can't seem to figure out what I'm missing. Here's some sample code:
---
ControlBase.cs
---
public class ControlBase : System.Web.UI.UserControl
{
private string _strTitle;
public string Title
{
get
{
return _strTitle;
}
set
{
_strTitle = value;
}
}
}
---
Default.aspx
---
<%@ Page language="c#" Codebehind="Default.aspx.cs" AutoEventWireup="false"
Inherits="namespace.PageBase" %>
....
<title><asp:literal id="litTitle" runat="server"></asp:literal></title>
---
Default.aspx.cs
---
public class PageBase : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Literal litTitle;
private ControlBase _ctlContent;
private void Page_PreRender(object sender, System.EventArgs e)
{
if (_ctlContent.Title != string.Empty)
{
this.litTitle.Text = _ctlContent.Title;
}
}
}
---
Default.ascx.cs
---
public class Default : ControlBase
{
private void Page_Load(object sender, System.EventArgs e)
{
this.Title = "This should be the title of the document";
}
}