473,394 Members | 1,902 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

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

</div>
</form>
</body>
</html>

--==========
Code behind

protected void Button1_Click1(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
Sep 24 '08 #1
2 1529
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

<go*******@gmail.comwrote in message
news:e8**********************************@26g2000h sk.googlegroups.com...
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://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

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

</div>
</form>
</body>
</html>

--==========
Code behind

protected void Button1_Click1(object sender, EventArgs e)
{
Label1.Text = DateTime.Now.ToString();
}
Sep 24 '08 #2
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.
Sep 29 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Martin | last post by:
Dear Group It says in MSDN that a field can be associated with more than one validators but can one validator be associated with more than one field? Or do I need a validator for each field? How...
0
by: Dhanashree | last post by:
I have a RangeValidator which uses AJAX to call server-side validation function from the client. The code works fine, but I have one problem. following is my range validator class: public...
3
by: Sandman | last post by:
So, I've used ajax for quite some time for different stuff. Mostly I just feed a funktion I made with the ID of the DIV that should be updated with the output from page XXX.php Now I want to...
5
by: lucyh3h | last post by:
Hi, I am trying to use XMLHttpRequest to do server side validation. I have several fields on a form and a submit button. The submit button has an event assocated with it when clicked. The...
7
ak1dnar
by: ak1dnar | last post by:
Hi, I got this scripts from this URL There is Error when i submit the form. Line: 54 Error: 'document.getElementbyID(....)' is null or not an object What is this error. Complete Files
2
by: Jeremy | last post by:
How would I go about using a custom validator to make a server side call using ajax?
8
omerbutt
by: omerbutt | last post by:
hi there i have a form with multiple input (type/text ) fields and three inputs(type/file) fields i have to submit the form via ajax because i have multiple forms on this page ,you can say it is a...
1
by: Stratum | last post by:
I use ASP.Net Validator controls on some Web pages, specifically, the Required Field Validator which works on the client side before a postback. The page has worked fine for some time. After I...
2
by: Alec MacLean | last post by:
Hi, I have a page using AJAX. The page has three modal popups that work fine when I don't have field validators in place. As soon as I put a validator in place, the popup "form" the validator...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.