Mike Andrews
2007-03-29 20:47:00 UTC
Guys,
I'm really lost now. I cannot, I repeat cannot, get the data in my
container control that represents the template to work.
If you notice in my markup, I have this: <%# Container.Text %>. When the
template control is created (MyContainer) and I call the Instantiate, this
value is not replaced with the message "The default container text!" as it
should have been, but instead is replaced with nothing.
Any help would be most appreciated. I'm really at my wits end with this
one.
Thanks,
Mike
Here's my asp.net markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<%@ Register Assembly="Scanner" Namespace="Scanner" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:ScannerControl id="ScannerControl1_1" runat="server">
<Template>
<h1><%# Container.Text %></h1>
</Template>
</cc1:ScannerControl>
</div>
</form>
</body>
</html>
Here's the result of the page when it's run:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJNTgwMjcwMjU1ZGTpLl3HHZKhrXybhi5mD/cUEBCBwQ==" />
</div>
<div>
<span id="ScannerControl1_1">
<h1></h1>
</span>
</div>
</form>
</body>
</html>
Here is a really scaled down version of my code:
[ToolboxData("<{0}:ScannerControl runat=server></{0}:ScannerControl>")]
public class ScannerControl : WebControl {
private ITemplate _template;
[TemplateContainer(typeof(MyContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate Template {
get { return _template; }
set { _template = value; }
}
protected override void CreateChildControls() {
this.Controls.Clear();
if (this.Template != null) {
MyContainer mc = new MyContainer("The default container
text!");
this.Template.InstantiateIn(mc);
this.Controls.Add(mc);
}
base.CreateChildControls();
}
}
public class MyContainer : Control, INamingContainer {
public MyContainer(string text) {
this.Text = text;
}
private string _text;
public string Text {
get { return _text; }
set { _text = value; }
}
}
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com
I'm really lost now. I cannot, I repeat cannot, get the data in my
container control that represents the template to work.
If you notice in my markup, I have this: <%# Container.Text %>. When the
template control is created (MyContainer) and I call the Instantiate, this
value is not replaced with the message "The default container text!" as it
should have been, but instead is replaced with nothing.
Any help would be most appreciated. I'm really at my wits end with this
one.
Thanks,
Mike
Here's my asp.net markup:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<%@ Register Assembly="Scanner" Namespace="Scanner" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:ScannerControl id="ScannerControl1_1" runat="server">
<Template>
<h1><%# Container.Text %></h1>
</Template>
</cc1:ScannerControl>
</div>
</form>
</body>
</html>
Here's the result of the page when it's run:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head><title>
Untitled Page
</title></head>
<body>
<form name="form1" method="post" action="Default.aspx" id="form1">
<div>
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE"
value="/wEPDwUJNTgwMjcwMjU1ZGTpLl3HHZKhrXybhi5mD/cUEBCBwQ==" />
</div>
<div>
<span id="ScannerControl1_1">
<h1></h1>
</span>
</div>
</form>
</body>
</html>
Here is a really scaled down version of my code:
[ToolboxData("<{0}:ScannerControl runat=server></{0}:ScannerControl>")]
public class ScannerControl : WebControl {
private ITemplate _template;
[TemplateContainer(typeof(MyContainer))]
[PersistenceMode(PersistenceMode.InnerProperty)]
public ITemplate Template {
get { return _template; }
set { _template = value; }
}
protected override void CreateChildControls() {
this.Controls.Clear();
if (this.Template != null) {
MyContainer mc = new MyContainer("The default container
text!");
this.Template.InstantiateIn(mc);
this.Controls.Add(mc);
}
base.CreateChildControls();
}
}
public class MyContainer : Control, INamingContainer {
public MyContainer(string text) {
this.Text = text;
}
private string _text;
public string Text {
get { return _text; }
set { _text = value; }
}
}
===================================
This list is hosted by DevelopMentor® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com