473,732 Members | 2,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

A bug in apsx client-side validation?

Recently, I was trying to modify an existing aspx page when client-side
validation on that page stopped working. I searched this group and the web
in general and found that other people have had the same issue. However,
none of the suggested fixes solved my particular problem. I tracked down the
cause of the problem, which is related to aspx page parser's handling of
controls inside html comments. The problem may be quite common and well
known. However, since I was not able to find an explanation anywhere, I am
going post my findings in case others run into the same issue.

The problem is related to how aspx page parser translates apsx controls
inside html comments. For example, the following code

<!--
<asp:TextBox id="TextBox1" runat="server"> </asp:TextBox>
-->

generates the following html

<!--
<input name="TextBox1" type="text" id="TextBox1" />
-->

Essentially, the parser ignores the comment and renders the control in html.
This presents no problem because the rendered html is enclosed inside html
comment and will be ignored by the browser. However, if there is a
validation control inside a html comment, such as the code below,

<!--
<asp:TextBox id="TextBox1" runat="server"> </asp:TextBox>
<asp:RequiredFi eldValidator id="rfvTextBox1 " runat="server"
ControlToValida te="TextBox1"> </asp:RequiredFie ldValidator>
-->

a problem occurs. The parser translates this comment into

<!--
<input name="TextBox1" type="text" id="TextBox1" />
<span id="rfvTextBox1 " controltovalida te="TextBox1"
evaluationfunct ion="RequiredFi eldValidatorEva luateIsValid" initialvalue=""
style="color:Re d;visibility:hi dden;"></span>
-->

The parser also adds the following javascript to the rendered page

<script language="javas cript" type="text/javascript">
<!--
var Page_Validators = new Array(document. all["rfvFName"],
document.all["rfvLName"], document.all["rfvEmail"],
document.all["rfvTextBox 1"]);
// -->
</script>

In addition to the required field validator shown above, there are several
other validation controls on my page and all of them are listed in the array
Page_Validators . The issue is that document.all["rfvTextBox 1"] always
returns null because it is enclosed inside html comment. The problem hits
home when client-side validation is initialized during a page load. Below is
the initialization function, copied exactly from WebUIValidation .js,

function ValidatorOnLoad () {
if (typeof(Page_Va lidators) == "undefined" )
return;
var i, val;
for (i = 0; i < Page_Validators .length; i++) {
val = Page_Validators[i];
if (typeof(val.eva luationfunction ) == "string") {
eval("val.evalu ationfunction = " + val.evaluationf unction +
";");
}
if (typeof(val.isv alid) == "string") {
if (val.isvalid == "False") {
val.isvalid = false;
Page_IsValid = false;
}
else {
val.isvalid = true;
}
} else {
val.isvalid = true;
}
if (typeof(val.ena bled) == "string") {
val.enabled = (val.enabled != "False");
}
ValidatorHookup ControlID(val.c ontroltovalidat e, val);
ValidatorHookup ControlID(val.c ontrolhookup, val);
}
Page_Validation Active = true;
}

This function hooks up each validators defined in the Page_Validators array.
However, as in the example given above, the last validator is null and the
code does not guard against nulls! This results in an exception, and the
variable Page_Validation Active is never set to true, effectively turning off
client-side validation.

Hong Hao
Nov 19 '05 #1
1 3949
> Recently, I was trying to modify an existing aspx page when client-side
validation on that page stopped working. I searched this group and the web in
general and found that other people have had the same issue. However, none of
the suggested fixes solved my particular problem. I tracked down the cause of
the problem, which is related to aspx page parser's handling of controls
inside html comments. The problem may be quite common and well known.
However, since I was not able to find an explanation anywhere, I am going
post my findings in case others run into the same issue.

The problem is related to how aspx page parser translates apsx controls
inside html comments. For example, the following code

<!--
<asp:TextBox id="TextBox1" runat="server"> </asp:TextBox>
-->

generates the following html

<!--
<input name="TextBox1" type="text" id="TextBox1" />
-->

Essentially, the parser ignores the comment and renders the control in html.
This presents no problem because the rendered html is enclosed inside html
comment and will be ignored by the browser. However, if there is a validation
control inside a html comment, such as the code below,

<!--
<asp:TextBox id="TextBox1" runat="server"> </asp:TextBox>
<asp:RequiredFi eldValidator id="rfvTextBox1 " runat="server"
ControlToValida te="TextBox1"> </asp:RequiredFie ldValidator>
-->

a problem occurs. The parser translates this comment into

<!--
<input name="TextBox1" type="text" id="TextBox1" />
<span id="rfvTextBox1 " controltovalida te="TextBox1"
evaluationfunct ion="RequiredFi eldValidatorEva luateIsValid" initialvalue=""
style="color:Re d;visibility:hi dden;"></span>
-->

The parser also adds the following javascript to the rendered page

<script language="javas cript" type="text/javascript">
<!--
var Page_Validators = new Array(document. all["rfvFName"],
document.all["rfvLName"], document.all["rfvEmail"],
document.all["rfvTextBox 1"]);
// -->
</script>

In addition to the required field validator shown above, there are several
other validation controls on my page and all of them are listed in the array
Page_Validators . The issue is that document.all["rfvTextBox 1"] always returns
null because it is enclosed inside html comment. The problem hits home when
client-side validation is initialized during a page load. Below is the
initialization function, copied exactly from WebUIValidation .js,

function ValidatorOnLoad () {
if (typeof(Page_Va lidators) == "undefined" )
return;
var i, val;
for (i = 0; i < Page_Validators .length; i++) {
val = Page_Validators[i];
if (typeof(val.eva luationfunction ) == "string") {
eval("val.evalu ationfunction = " + val.evaluationf unction + ";");
}
if (typeof(val.isv alid) == "string") {
if (val.isvalid == "False") {
val.isvalid = false;
Page_IsValid = false;
}
else {
val.isvalid = true;
}
} else {
val.isvalid = true;
}
if (typeof(val.ena bled) == "string") {
val.enabled = (val.enabled != "False");
}
ValidatorHookup ControlID(val.c ontroltovalidat e, val);
ValidatorHookup ControlID(val.c ontrolhookup, val);
}
Page_Validation Active = true;
}

This function hooks up each validators defined in the Page_Validators array.
However, as in the example given above, the last validator is null and the
code does not guard against nulls! This results in an exception, and the
variable Page_Validation Active is never set to true, effectively turning off
client-side validation.

Hong Hao


True, the parser looks just for "runat=serv er" controls and ignores
client-side comment brackets. This might be by design: you could put
a Label there to render client-side comments.
Unfortunately this has the side-effect that you noticed.

A couple of ways around it:
- use server-side comments: <%!-- --%>
- remove the "runat=serv er" (I usually "destroy" it by adding an "X":
runXat=server is not recognised and ignored)

Hans Kesting
Nov 19 '05 #2

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

Similar topics

15
4489
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do computations, the only data transfered is user mouse/kbd input. It works synchronously, but somehow, when I play in client window, both client and server have 17 fps, while when playing in server window, server has 44 fps while client ...
2
3034
by: Raquel | last post by:
How do I know whether the 'runtime client' and the 'application development client' are installed on my machine? When I issue the command "db2licm -l", it gives the following output: Product Name = "DB2 Personal Edition" Product Password = "DB2PE" Version Information = "8.1" Expiry Date = "Permanent" Annotation = "" Other information = ""
2
4668
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info Center: To return a result set from a procedure to the originating application, use the WITH RETURN TO CLIENT clause. When WITH RETURN TO CLIENT is specified on a result set, no nested procedures can access the result set.
2
7574
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking. Any help appreciated! The ordeal is a follows I am using Solaris 10 with php5.1.1. GCC:
0
1745
by: khu84 | last post by:
Here is client server very simple code, seems to work with telnet but with with web client code gives blank output. Following is the server code:- <?php function createSocketServer($host='192.168.1.34',$port=2222) { $max_clients = 10;
1
1762
by: coolsidsin | last post by:
I have a apsx form (Form A), which on submiting does a time consuming task. So i want to open a new aspx window (Form B) in which I want do do that time consuming task and show progress to the user and while that task is being completed I want Form A to redirect to Form C. I opened form B in a new javascript window and updated the progress through ajax but Form A doesn't let me redirect to Form C unless Form B's processing is Completed. ...
2
4101
by: nsaffary | last post by:
hi I hava a client/server program that run correctly when i run it in one computer(local) but when I run client on a one computer and run server run on another, connection does not stablish.(I set server machine IP for client and server) please guide me? server : #include <winsock2.h> #include <iostream> #include <stdio.h> #include <string.h> #include <windows.h> #pragma comment(lib, "ws2_32");
8
5731
by: abdunnabisk | last post by:
Any body has any idea on How to call apsx.cs mthod(C#) from javascript? Thanks Abdun Nabi Sk
0
8944
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9445
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9234
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9180
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6030
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4548
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4805
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3259
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 we have to send another system
3
2177
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.