Re: Template data is not being replaced in a Templated ASP.NET server control...
Mike Andrews <[email protected]>
| Newsgroups | gmane.comp.windows.devel.dotnet.web |
|---|---|
| Message-ID | <[email protected]> |
Thanks for the response Adam. Would you be able to provide an example? I'm not sure what you mean about the DataBind on the scanner control. Thanks, Mike On 3/29/07, Adam Sills <[email protected]> wrote: > > You have two problems. > > 1. You're not calling DataBind on your scanner control > 2. WebControl by itself does not loop through its child controls and call > DataBind on them in its DataBind call. You need to do that yourself or > inherit from CompositeControl instead. > > Adam.. > > -----Original Message----- > From: Discussion of building .NET applications targeted for the Web > [mailto:[email protected]] On Behalf Of Mike Andrews > Sent: Thursday, March 29, 2007 3:47 PM > To: [email protected] > Subject: [DOTNET-WEB] Template data is not being replaced in a Templated > ASP.NET server control... > > 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 DevelopMentorR http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com > > =================================== > This list is hosted by DevelopMentor(r) http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com > =================================== This list is hosted by DevelopMentor® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com