473,395 Members | 1,454 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,395 software developers and data experts.

Hidden validators cause javascript error

I have a web form that contains a Datagrid. This grid has a number of
columns, one of which contains a text box and validator for that text box.
Everything works fine, when I press the "Save" button the validator works as
expected...however...

....I want to hide certain columns under certain conditions. One of the
columns I wish to hide is the column that contains the text box and the
validator. This is done by something like

grdAddItem.Columns[5].Visible = false;

in the code behind.

Now the page renders fine, but when I press the Save button I get a
javascript error "Page_Validators is undefined". The validator is contained
within the form and the form does have runat=server set.

Am I missing something? or is this a bug?

I have found a workaround for this problem which is to add another validator
to the form together with a text box for it it to validate and make them
both invisble and set up so that the new validator always validates. If I do
this I no longer get the javascript error.
e.g.
<asp:TextBox ID=txtTest Runat=server Visible=False>1</asp:TextBox>
<asp:CompareValidator ID="Comparevalidator3" Type="Integer"
ControlToValidate="txtTest" ErrorMessage=""
Runat="server" Operator="DataTypeCheck" CssClass="errorMessage"
Display="None" ValueToCompare="1"></asp:CompareValidator>

Any ideas?

Cheers
Ian
Nov 19 '05 #1
4 1867
Hi Lan,

From your description, you have a datagrid which contains a textbox and a
validation control in a certain column. You found that there will occur
script error("Page_validators undefined") when you hidden that column and
click a certain button(causevalidtion) to submit the page, yes?

As for the problem, I've also done some simple tests and did see the this
behavior. I think the problem is because normally the webform will generate
the following script code (enable client side validation) when there is
validators on the page and use client side valiation:

<script language="javascript" type="text/javascript">
<!--
var Page_Validators = new Array(document.all["dgMain__ctl2_rfvItem"],
document.all["dgMain__ctl3_rfvItem"], document.all["dgMain__ctl4_rfvItem"],
document.all["dgMain__ctl5_rfvItem"], document.all["dgMain__ctl6_rfvItem"]);
// -->
</script>
the code create an Array that hold all the validtor elements on page.
However, when we hidden the column( which means we hidden those
validators), the above code disappeared. But since our asp.net
submit Button is "causeValidtion=true" , so when we hit the button, the
clientside script will still looking for the

"Page_Validtors" variable but failed to find it which lead to the error you
encountered. So I suggest that we turn off the button's causeValidation
when we hidden the validators on the page since no validation is needed at
that time. How do you think?

If there is anything unclear, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Nov 19 '05 #2
Thanks Steven. That makes sense to me, and the suggested solution works.

Thanks for your help

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:2Q**************@cpmsftngxa10.phx.gbl...
Hi Lan,

From your description, you have a datagrid which contains a textbox and a
validation control in a certain column. You found that there will occur
script error("Page_validators undefined") when you hidden that column and
click a certain button(causevalidtion) to submit the page, yes?

As for the problem, I've also done some simple tests and did see the this
behavior. I think the problem is because normally the webform will generate the following script code (enable client side validation) when there is
validators on the page and use client side valiation:

<script language="javascript" type="text/javascript">
<!--
var Page_Validators = new Array(document.all["dgMain__ctl2_rfvItem"],
document.all["dgMain__ctl3_rfvItem"], document.all["dgMain__ctl4_rfvItem"], document.all["dgMain__ctl5_rfvItem"], document.all["dgMain__ctl6_rfvItem"]); // -->
</script>
the code create an Array that hold all the validtor elements on page.
However, when we hidden the column( which means we hidden those
validators), the above code disappeared. But since our asp.net
submit Button is "causeValidtion=true" , so when we hit the button, the
clientside script will still looking for the

"Page_Validtors" variable but failed to find it which lead to the error you encountered. So I suggest that we turn off the button's causeValidation
when we hidden the validators on the page since no validation is needed at
that time. How do you think?

If there is anything unclear, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #3
There is a bug in the DataGrid that I confirmed with Microsoft about a year
ago. When a control that outputs javascript is contained in a header, footer
or column that is hidden, the javascript is still output, but the HTML is
not. In this case, the validator outputs itself into the Page_Validators
array. When that array is created, it expects to convert
document.all[validatorid] into an object. It does not. The validator scripts
which iterate through Page_Validators are not expecting a null in
Page_Validators and invoke the error.

Solution: any control that outputs javascript should explicitly be set to
Visible=false when the header, footer, or column containing it is hidden.

--- Peter Blum
www.PeterBlum.com
Email: PL****@PeterBlum.com
Creator of "Professional Validation And More" at
http://www.peterblum.com/vam/home.aspx

"Steven Cheng[MSFT]" <v-******@online.microsoft.com> wrote in message
news:2Q**************@cpmsftngxa10.phx.gbl...
Hi Lan,

From your description, you have a datagrid which contains a textbox and a
validation control in a certain column. You found that there will occur
script error("Page_validators undefined") when you hidden that column and
click a certain button(causevalidtion) to submit the page, yes?

As for the problem, I've also done some simple tests and did see the this
behavior. I think the problem is because normally the webform will
generate
the following script code (enable client side validation) when there is
validators on the page and use client side valiation:

<script language="javascript" type="text/javascript">
<!--
var Page_Validators = new Array(document.all["dgMain__ctl2_rfvItem"],
document.all["dgMain__ctl3_rfvItem"],
document.all["dgMain__ctl4_rfvItem"],
document.all["dgMain__ctl5_rfvItem"],
document.all["dgMain__ctl6_rfvItem"]);
// -->
</script>
the code create an Array that hold all the validtor elements on page.
However, when we hidden the column( which means we hidden those
validators), the above code disappeared. But since our asp.net
submit Button is "causeValidtion=true" , so when we hit the button, the
clientside script will still looking for the

"Page_Validtors" variable but failed to find it which lead to the error
you
encountered. So I suggest that we turn off the button's causeValidation
when we hidden the validators on the page since no validation is needed at
that time. How do you think?

If there is anything unclear, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #4
You're welcome Lan,

Have a good day!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 19 '05 #5

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

Similar topics

2
by: Christian H | last post by:
Based on the content in my database, I need to populate different form controls and validators, such as textbox, dropdownlist, requiredfieldvalidators , etc. Then I need to check if the form has...
1
by: cksj | last post by:
I have a button that will trigger validators. In one special case, I have to show a message box when the button is clicked. In the code behind, I added the following: ...
2
by: Axel Dahmen | last post by:
Hi, I've added a couple of validators to my page. Now I get a couple of Runtime Errors when I load the page (I have "Show client-script errors" enabled in IE6): "A Runtime Error has occurred....
2
by: Mike Surcouf | last post by:
Hi I have some regex validators on my page set to dynamic and like the way they appear after you tab out of a field and also when you try to postback the form. All OK so far When I register...
3
by: rgparkins | last post by:
Hi I am currently having problems with Validators in a user control. I am creating a wizard sign-up process which have the allocated step (hyperlinks" at the top of the page. A user can also...
0
by: news.microsoft.com | last post by:
I am going crazy trying to figure this out, and I am wondering if this is a bug in the ASP.Net implementation. My situation: I have an ASPX page with 2 different modes: *Mode 1: Datagrid...
4
by: reikoshea | last post by:
okay ive been working at this for probably 4 hours now, and I (not to mention my boss) am pretty upset. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head>...
8
by: ShaneFowlkes | last post by:
For some reason, my validator controls stopped working when a form posts. They seems to work on fields that lose focus but if I submit a form with all empty fields, not of the required validators...
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
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,...
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
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
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.