469,934 Members | 1,873 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

validators not firing server-side

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
Jan 7 '08 #1
1 2913
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/subscripti...ult.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/subscripti...t/default.aspx.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Andrew Jocelyn" <j0**@newsgroups.nospam>
Subject: validators not firing server-side
Date: Mon, 7 Jan 2008 11:21:43 -0000

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
Jan 8 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by RichieRich | last post: by
7 posts views Thread by Bill Richardson | last post: by
7 posts views Thread by angus | last post: by
6 posts views Thread by Mark | last post: by
4 posts views Thread by Luis Esteban Valencia | last post: by
1 post views Thread by tshad | last post: by
reply views Thread by tshad | last post: by
reply views Thread by Mike Collins | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.