validators not firing server-side

A

Andrew Jocelyn

Hi

I have a Formview control in a UserControl. The server-side validation is
not working, i.e. the events are not firing when a button control which
causes validation is fired or even when Page.Validate() is explicitly
called.

I'm loading the FormView as an IBindableTemplate as in this article but I
don't think this is the reason for the validation not working.
http://www.developerfusion.co.uk/show/4721/

I have a couple of custom validators in the user control which bubble the
events to the parent page. These don't fire. However I have tested in
another simpler version of the page and they do fire.

What can I do to determine why the validation doesn't work? What can cause
it to stop working? How do I debug?

Thanks
Andrew
 
S

Steven Cheng[MSFT]

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>
&nbsp;<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.

--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top