473,485 Members | 1,457 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

ASP.NET 2.0 Callback Validation

Hello,

I am trying to use a CustomValidator control to perform client-side
validation via a server callback.

I have an example below that validates if a textbox contains an odd
number.

I realize that I can use client-side javascript entirely for this, I
have just created a simplified example. My actual callback validation
routine involves accessing a database but I figured a simplified
example would be better.

The callback validation in my code seems to work ok, and returns the
result correctly to the CallBackReturnFunction() javascript function,
however it does not seem to be able to pass the IsValid values
correctly at the end of the function.

Any input would be appreciated.

The codebehind for this page is located here:
http://rainz.org/code/codebehind.txt

Here is the page code:

<%@ Page Language="VB" AutoEventWireup="false"
CompileWith="OddTest.aspx.vb" ClassName="OddTest_aspx" %>

<html>
<head>
<title>Odd Number Callback Validation</title>

<script language="javascript">
function ClientValidate(source, arguments) {

var message = arguments.Value;

// create context variable
var oContext = new Object();
oContext.args = arguments;

<%=sCallBackFunctionInvocation%>
}

function CallBackReturnFunction(sReturnValue, oContext) {
var result='The callback return value is ' +
sReturnValue + '\n';
if (sReturnValue=='true')
{result = result + 'ODD Number, Validation Passed'}
else
{result = result + 'NOT Odd Number, Validation
Failed'}

alert(result);

if (sReturnValue == 'true') { /*validation passed*/
oContext.args.IsValid=true
}
else { /*validation failed*/
oContext.args.IsValid=false
}
}
function OnError(message, oContext) {
alert('An unhandled exception has occurred:\n' + message);
}

</script>
</head>
<body>
<form id="form1" runat="server">
<asp:Label id="Message"
Text="Enter an odd number:"
Font-Names="Verdana"
Font-Size="10pt"
runat="server"/>

<asp:TextBox id="Text1"
runat="server" />&nbsp;&nbsp;

<asp:CustomValidator id="CustomValidator1"
ControlToValidate="Text1"
ClientValidationFunction="ClientValidate"
OnServerValidate="ServerValidation"
Display="Static"
ErrorMessage="Not an odd number!"
ForeColor="green"
Font-Names="verdana"
Font-Size="10pt"
runat="server"/>

<p>
Leave blank for testing, prevents server validation, we want
to verify client callback validation:
<asp:TextBox ID="Text2" Runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1"
Runat="server" ErrorMessage="*required"
ControlToValidate="Text2">
</asp:RequiredFieldValidator>
<br />
<br />
<asp:Button ID="Button1" Runat="server" Text="Button"
OnClick="Button1_Click" />&nbsp;
</p>

</form>
</body>
</html>
Nov 18 '05 #1
0 2152

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

Similar topics

0
2438
by: JULO | last post by:
Hi, I have this problem: In GridView I have template column with ImageButtons - for deleting row. When I click on that button I get this message Invalid postback or callback argument. Event...
2
13194
by: Ray Stevens | last post by:
Anyone see this error that appears to have cropped up with the RTM version of .NET: BASE EXCEPTION:: System.ArgumentException: Invalid postback or callback argument. Event validation is enabled...
2
5765
by: Mike P | last post by:
I have added a couple of buttons to my ASP.NET 2.0 page. which both are meant to do pretty simple things, a Back button and a Submit data button. But I get this error whenever I click either of...
1
17020
by: Timbo | last post by:
Hi all, This is my first message here so i'll try and include all the information that will help you help me out, if possible. Basically I am using C# in ASP.NET 2.0 and have a Repeater...
3
7390
by: Martin | last post by:
Hi, I have an aspx page with two dropdownlist controls. I update the options in the second ddl based on selection made in the first. I do this with the ICallbackEventHandler interface, as per...
7
5172
by: Varangian | last post by:
Hi all, I have a question, what does the function ClientScriptManager.RegisterForEventValidation really does? Does it means securing your client side code? more security? The question is how...
2
2153
by: Nathan Sokalski | last post by:
I have a DataList in which the ItemTemplate contains two Button controls that use EventBubbling. When I click either of them I receive the following error: Server Error in '/' Application....
9
4529
by: 200dogz | last post by:
Hi guys, I want to have a button which opens up a new window when pressed. <asp:Button ID="Button1" runat="server" Text="Open new window" /> ... Button1.Attributes.Add("OnClick",
0
7116
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,...
1
6825
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7275
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...
0
5418
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4857
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3058
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3063
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1376
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
247
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.