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

Mozilla client side validation does not work

I've created a page using VS.NET and page validator controls. The client
side validation works fine on IE, but does not even activate under
"alternate" browsers like Mozilla, Opera, etc. Why is this? I can't find any
differences on the pages produced, and Mozilla should be able to handle
everything IE can. How can I fix this?
Nov 17 '05 #1
2 2293
Ok, I threw in the towel and decided to implement it myself. It turns out it
is supprisingly simple and I've included it below for anyone in the same
boat as I.

Any questions I'm willing to help, my real email address is:
r . w a g n e r (at) c r o s s l i n k . c o m . a u

Below is the ASP.NET page. It is a login page and the javascript checks the
username and password field have been filled in. it works in the following
way:

- Nothing happens until the submit button is clicked the first time. When
the button is clicked the gbVaidating variable is set to true
- The gbValidate() function does the validating. It checks each field. If
the field is invalid, it make a div visible. It does this by changing the
the display property of the style attribute. If the filed is valid, it hides
the div.
- Everytime a textbox is changed, the validation is re-run, but only has an
effect after the first submit. This means that after the first submit, the
error messages will appear, but will dissapear after a correct value has
been entered.
- In the code behind page, you will need to add some custom attributes so
the button and fields run the javascript

*** Code behind page ***

private void Page_Load(object sender, System.EventArgs e) {

.....
btnLogin.Attributes.Add("OnClick", "return gbStartValidation()");
txtUsername.Attributes.Add("OnChange", "gbValidate()");
txtPassword.Attributes.Add("OnChange", "gbValidate()");

.....
}

*** ASP.NET code ***

<%@ Register TagPrefix="uc1" TagName="Footer" Src="Template/Footer.ascx" %>
<%@ Register TagPrefix="cc1" Namespace="Consus.Web" Assembly="ConsusWeb" %>
<%@ Page language="c#" Codebehind="Login.aspx.cs" AutoEventWireup="false"
Inherits="Consus.Web.Login" %>
<%@ Register TagPrefix="uc1" TagName="HeaderNoCheck"
Src="Template/HeaderNoCheck.ascx" %>
<%@ Register TagPrefix="uc1" TagName="Header" Src="Template/Header.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>Login</title>
<meta content="Microsoft Visual Studio 7.0" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
<script>

var gbValidating = false;

//
// Starts validation
// Validation should be started on the first click on the submit
//
function gbStartValidation() {
gbValidating = true;
return gbValidate();
}

//
// Validate the page if we have started validation
//
function gbValidate() {
var gbValid;

gbValid = true;

if(gbValidating) {

//
// Check username and password are filled in
//

if(document.Login.txtUsername.value.length == 0) {
document.getElementById("valUsername").style.displ ay = "inline";
gbValid = false;
} else {
document.getElementById("valUsername").style.displ ay = "none";
}

if(document.Login.txtPassword.value.length == 0) {
document.getElementById("valPassword").style.displ ay = "inline";
gbValid = false;
} else {
document.getElementById("valPassword").style.displ ay = "none";
}
}

return gbValid;
}
</script>
</HEAD>
<body>
<form id="Login" method="post" runat="server">
<uc1:headernocheck id="HeaderNoCheck1"
runat="server"></uc1:headernocheck>
<TABLE id="Table1" borderColor="#008f7c" cellSpacing="0"
borderColorDark="#004559" cellPadding="0" align="center" bgColor="#007bb5"
borderColorLight="#00d3b7" border="5">
<TBODY>
<tr>
<td>
<table>
</I></td>
</tr>
<TR>
<TD style="HEIGHT: 25px">
<P align="right"><FONT color="white" size="4">Username</FONT></P>
</TD>
<td style="HEIGHT: 25px" width="5"><FONT color="white"></FONT>
<TD style="HEIGHT: 25px"><FONT size="4"><asp:textbox id="txtUsername"
runat="server" Width="150px"></asp:textbox><FONT
color="white"></FONT></FONT></TD>
</TR>
<TR>
<TD style="HEIGHT: 5px">
<P align="right"><FONT color="white" size="4">Password</FONT></P>
</TD>
<td style="HEIGHT: 5px">
<TD style="HEIGHT: 5px"><asp:textbox id="txtPassword" runat="server"
Width="150px" TextMode="Password"></asp:textbox></TD>
</TR>
<TR>
<TD>
<td>
<TD>
<P align="right"><asp:button id="btnLogin" runat="server"
Text="Login"></asp:button></P>
</TD>
</TR>
<% //
// Show login failed if appropriate
//

if(gbLoginFailed) { %>
<tr>
<td colSpan="3"><FONT color="red"><STRONG>Invalid Username or
Password</STRONG></FONT>
</td>
</tr>
<% } %>
<tr>
<td colSpan="3">
<div id="valUsername" style="DISPLAY: none; COLOR: red">Please enter
a username</div>
</td>
</tr>
<tr>
<td colSpan="3">
<div id="valPassword" style="DISPLAY: none; COLOR: red">Please enter
a password</div>
</td>
</tr>
</TABLE>
</TD></TR></TBODY></TABLE><uc1:footer id="Footer1"
runat="server"></uc1:footer></form>
</body>
</HTML>
"Robert Wagner" <go**@swdeveloper.com.au> wrote in message
news:Oh*************@tk2msftngp13.phx.gbl...
I've created a page using VS.NET and page validator controls. The client
side validation works fine on IE, but does not even activate under
"alternate" browsers like Mozilla, Opera, etc. Why is this? I can't find any differences on the pages produced, and Mozilla should be able to handle
everything IE can. How can I fix this?

Nov 17 '05 #2
Just to stop some people getting frustrated, the code included is taken
directly from my project, so you'll have to take out the custom code :).
Can't do it all for ya.

"Robert Wagner" <go**@swdeveloper.com.au> wrote in message
news:uR**************@TK2MSFTNGP10.phx.gbl...
Ok, I threw in the towel and decided to implement it myself. It turns out it is supprisingly simple and I've included it below for anyone in the same
boat as I.

Any questions I'm willing to help, my real email address is:
r . w a g n e r (at) c r o s s l i n k . c o m . a u

<snip>
Nov 17 '05 #3

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

Similar topics

2
by: webbedfeet | last post by:
Hi I hope someone can help me. I have a client side form validation script which works perfectly in IE but clicking "Submit" in Mozilla does nothing - the form won't submit. Is there something I...
0
by: Robert Wagner | last post by:
As a side note to me previous post, I thought I might post about how ASP.Net does not detect the mozilla browser correctly. This means that archaic html is used and some things are not even printed...
5
by: Jonel Rienton | last post by:
Hi, i've created a simple web application and throw in some labels, textboxes and requiredfield validators in there. during my testing using different browsers, i've noticed that when i was...
4
by: | last post by:
Hello Guys, I am using the validation controls to validate my data. But the problem is "The page is still being posted to server". I want to get rid of the round trips to server. Are there...
1
by: Pai | last post by:
Hello there, I need to make my .aspx pages compatible with both these browsers... Could anybody guide me to some tutorials or some tips I just have a <table> tag and a few <td> and <tr> in...
2
by: msnews.microsoft.com | last post by:
Hi Every Body, I have build the website in asp.net using vb.net. I use the asp.net validation controls for client side validation. When I run the site in Internet Explorer, It run properly and...
1
by: rmgalante | last post by:
I have written an ASP.Net application that uses the standard client-side and server-side validation for various fields on the form. Some of the customers that use the form report symptoms that...
2
by: Nick | last post by:
hi, all I just notice, all validators in my pages don't work in Rethat Linux which is using Mozilla 1.2.1. Is there anyway to work around that? Thanks.
4
by: tshad | last post by:
I have a RegularExpressionValidator that is testing a field to make sure the number is between 0 and 255. It works fine in IE, but doesn't work in Mozilla or Firefox. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.