By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,644 Members | 2,423 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,644 IT Pros & Developers. It's quick & easy.

Mozilla client side validation does not work

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.