Ajax with field validator



How do I prevent field validator which resides outside of UpdatePanel
from firing off? The label will update correctly without
RequiredFieldValidator via Ajax. TIA.

Code below....

<%@ Page Language="C#" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication1._Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">

<asp:TextBox ID="TextBox1" runat="server"></
ID="RequiredFieldValidator1" runat="server"
ErrorMessage="Required" ControlToValidate="TextBox1">*</
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<asp:Label ID="Label1" runat="server" Text="Label"></
asp:Label><br />
<asp:Button ID="Button1"
runat="server" Text="Button" onclick="Button1_Click1" / </ContentTemplate>


Code behind

protected void Button1_Click1(object sender, EventArgs e)
Label1.Text = DateTime.Now.ToString();



Mark Fitzpatrick

You can group the fields via the validationgroup property, although this
doesn't exactly make sense because if you're trying to validate something
then it has to be fired with your button that's inside your updatepanel.
Another possibility is to disable the client-side validation on the
requiredfieldvalidator. This is good form anyways as you should never really
perform client-side validation since the validation script can be
circumvented on the browser.

Hope this helps,
Mark Fitzpatrick
Microsoft MVP - Expression




Thanks for replying and sorry for late post.

I resolved it by, like you said, putting and grouping
validationgroup. The sample I gave was for simplicity. My original
requirement was to have two drop down lists and have one fire off and
populate the second one. For example, first one is country and second
is the state. So on selectedindexchanged from first one, second will
populate states based on country selection. Thanks again.

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