Hi Andrew,
As for the article you mentioned, it use a usercontrol + a wrapper formview
to provide dynamic bindable template. The FormView in the usercontrol
should not be used. I think you've used the dynamic loaded template in the
main page(with some certain databound control), correct?
I have performed a simple test with the following page, it seems the
validator can correctly validate the textbox(both of them are within the
usercontrol...).
Here is the source code of the test page&user control
=========BindableTemplate.ascx=========
<%@ Control %>
<asp:FormView ID="dd" runat="server">
<ItemTemplate>
<asp:Label ID="lbl" runat="server" Text='<%Bind("id")
%>'></asp:Label><br />
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
ErrorMessage="RequiredFieldValidator"
ControlToValidate="TextBox1"
EnableClientScript="false"></asp:RequiredFieldValidator> <br />
<asp:Button ID="Button1" runat="server" Text="Button"
CausesValidation="false"/>
</ItemTemplate>
</asp:FormView>
=======================
=====test aspx page============
<form id="form1" runat="server">
<div>
<asp:Button ID="btnTree" runat="server"
OnClick="btnTree_Click" Text="Page Button" CausesValidation="False" /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CacheDBConnectionString %>"
SelectCommand="SELECT [id], [name], [description] FROM
[cache_table]"></asp:SqlDataSource>
<br />
<asp:FormView ID="FormView1" runat="server" DefaultMode="readonly"
DataSourceID="SqlDataSource1">
</asp:FormView>
</div>
</form>
=======code behind=============
..........
protected void Page_Init(object sender, EventArgs e)
{
FormView1.ItemTemplate =
LoadBindableTemplate("~/BindableTemplate.ascx");
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnTree_Click(object sender, EventArgs e)
{
Page.Validate();
}
IBindableTemplate LoadBindableTemplate(string path)
{
Control c = Page.LoadControl(path);
FormView fv = c.Controls[0] as FormView;
if (fv == null) throw new Exception("invalid template file");
return (IBindableTemplate)fv.ItemTemplate;
}
===========================
please feel free to let me know if there is anything else different in your
case.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------