validators not firing server-side

validators not firing server-side

am 07.01.2008 12:21:43 von J055

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

RE: validators not firing server-side

am 08.01.2008 09:40:32 von stcheng

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 %>





ErrorMessage="RequiredFieldValidator"
ControlToValidate="TextBox1"
EnableClientScript="false">


CausesValidation="false"/>


=======================

=====test aspx page============



  OnClick="btnTree_Click" Text="Page Button" CausesValidation="False" />

ConnectionString="<%$ ConnectionStrings:CacheDBConnectionString %>"
SelectCommand="SELECT [id], [name], [description] FROM
[cache_table]">



DataSourceID="SqlDataSource1">






=======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/de fault.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.

--------------------
>From: "Andrew Jocelyn"
>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
>
>
>