I will show you a piece of code that worked with the last CTP:
<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="test.aspx.cs"Inherits="test" %>
<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<htmlxmlns="http://www.w3.org/1999/xhtml">
<headrunat="server">
<title>Databound Controls</title>
</head>
<body>
<formid="form1"runat="server">
<atlas:ScriptManagerEnablePartialRendering=trueID="sm"runat="server"></atlas:ScriptManager>
<
asp:RepeaterID="rpt"runat="server"DataSourceID="xmlData"OnItemDataBound="rpt_ItemDataBound"><ItemTemplate>
<%# XPath("name") %><asp:TextBoxID="textInside"runat="server"></asp:TextBox><br/>
<atlastoolkit:TextBoxWatermarkExtenderID="watInside"TargetControlID="textInside"runat="server"WatermarkText="Inside TextBox"/>
</ItemTemplate>
</asp:Repeater>
Somebody<asp:TextBoxID="textOutside"runat="server"></asp:TextBox><br/>
<atlastoolkit:TextBoxWatermarkExtenderID="watOutside"runat="server"TargetControlID="textOutside"WatermarkText="Outside TextBox"/>
<asp:XmlDataSourceID="xmlData"runat="server"XPath="contacts">
<Data>
<contacts>
<name>Peter</name>
</contacts></Data>
</asp:XmlDataSource>
</form>
</body>
</html>
This piece of code is not working anymore more. The responsible is the “new” behaviour of the TargetControlID. Now, you need the ClientID of the target control, not the usual control ID.
In the easy case, both (ClientID and ID) are the same, but not inside databound controls. So what you need now is:
First, you need to DataBind() the Page at load stage; this is because you need the extender controls in the control tree before the (Pre)Render stage; otherwise, they won’t render.
Second, you need to delete the TextBoxWatermarkExtender instantiated declaratively, and add it at runtime:
protectedvoid rpt_ItemDataBound(object sender,RepeaterItemEventArgs e)
{
AjaxControlToolkit.TextBoxWatermarkExtender tbe =new AjaxControlToolkit.TextBoxWatermarkExtender ();
tbe.TargetControlID = (e.Item.FindControl("textInside")asTextBox).ClientID;
tbe.ID ="watInside";
tbe.WatermarkText ="Inside Text";
tbe.ResolveControlID +=new AjaxControlToolkit.ResolveControlEventHandler(tbe_ResolveControlID);
e.Item.Controls.Add(tbe);
}
Finally, the extender control is not still able to find the TargetControlID, so you have to make up your own FindControl (like this one) :
void tbe_ResolveControlID(object sender, AjaxControlToolkit.ResolveControlEventArgs e)
{
e.Control =Util.FindControl(e.ControlID,"_",this.Page);
}
publicstatic System.Web.UI.Control Util.FindControl(string cliendid,string separator, System.Web.UI.Control root)
{
int i = 0;
string[] sepControls = cliendid.Split(separator[0]);
System.Web.UI.Control fc =null;
for (fc = root; (null != fc) && i < sepControls.Length; i++)
{
fc = fc.FindControl(sepControls[i]);
}
if (fc !=null && fc.ClientID == cliendid)return fc;
elsereturnnull;
}
If someone knows any other way to simplify this case, please tell me. Otherwise, my project has become a nightmare.
fran
Your original sample works fine for me with the addition of only:
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
rpt.DataBind();
}
More details here:http://forums.asp.net/thread/1441672.aspx.
No comments:
Post a Comment