473,749 Members | 2,432 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Web Form validation with 2 forms on a single page

I have a site where I want to use the Web form validators in two separate
forms on a single page. One form allows existing users to log in while the
second one allows new users to register. The problem is that if I use the
Web Form validation tags, it treats them all as one form (ie...if someone is
trying to use the login form, they get an error saying that they have to
enter values in the registration form and vice-versa).

Any ideas on how to handle this?
Nov 17 '05 #1
1 4525
19765604

Hi,

On the client, you need to use a function named ValidatorEnable to turn
specific validators on or off. On the server, you need to override the
Validate event and add code to enable/disable specific validators.

Notice that I'm careful to replicate the enable/disable state of each
validator in the server Validate event to be the same state as it was on
the client. Errors here could cause bugs that are hard to track down.

The following sample uses two text boxes for users to login & two for new
users to sign up. All four have required field validators. (with this
simple example, it would have been more elegant to use just one set of two
text boxes. However, I expect that your login & sign-up sections are
different from each other).

This whole sample has almost no error handling since it's just a sample.
The "broken" mode merely turns on all validators on the server & blocks
almost any activity,
**** CODE-BEHIND

Public Overrides Sub Validate()
RequiredFieldVa lidator1.Enable d = (Mode.Value = "Broken" Or Mode.Value
= "Login")
RequiredFieldVa lidator2.Enable d = (Mode.Value = "Broken" Or Mode.Value
= "Login")
RequiredFieldVa lidator3.Enable d = (Mode.Value = "Broken" Or Mode.Value
= "NewUser")
RequiredFieldVa lidator4.Enable d = (Mode.Value = "Broken" Or Mode.Value
= "NewUser")
MyBase.Validate ()
End Sub

**** ASPX PAGE

<HTML>
<HEAD>
<title>Validate dLogin1</title>
<meta content="Micros oft Visual Studio .NET 7.1" name="GENERATOR ">
<meta content="Visual Basic .NET 7.1" name="CODE_LANG UAGE">
<meta content="JavaSc ript" name="vs_defaul tClientScript">
<meta content="http://schemas.microso ft.com/intellisense/ie5"
name="vs_target Schema">
<script>

function ToLogin() {
Form1.Mode.valu e = "Broken"
Form1.Button1.v alue = "Login";
Form1.Button2.v alue = "New visitors click here";
Form1.TextBox1. disabled="";
Form1.TextBox2. disabled="";
Form1.TextBox3. disabled="disab led";
Form1.TextBox4. disabled="disab led";
Form1.TextBox1. style.visibilit y = "";
Form1.TextBox2. style.visibilit y = "";
Form1.TextBox3. style.visibilit y = "hidden";
Form1.TextBox4. style.visibilit y = "hidden";
ValidatorEnable (RequiredFieldV alidator1, true);
ValidatorEnable (RequiredFieldV alidator2, true);
ValidatorEnable (RequiredFieldV alidator3, false);
ValidatorEnable (RequiredFieldV alidator4, false);
Form1.TextBox3. value="";
Form1.TextBox4. value="";
Form1.Mode.valu e = "Login"
}

function ToNewUser() {
Form1.Mode.valu e = "Broken"
Form1.Button1.v alue = "Click here if you already have an account";
Form1.Button2.v alue = "Register new name and password";
Form1.TextBox1. disabled="disab led";
Form1.TextBox2. disabled="disab led";
Form1.TextBox3. disabled="";
Form1.TextBox4. disabled="";
Form1.TextBox1. style.visibilit y = "hidden";
Form1.TextBox2. style.visibilit y = "hidden";
Form1.TextBox3. style.visibilit y = "";
Form1.TextBox4. style.visibilit y = "";
ValidatorEnable (RequiredFieldV alidator1, false);
ValidatorEnable (RequiredFieldV alidator2, false);
ValidatorEnable (RequiredFieldV alidator3, true);
ValidatorEnable (RequiredFieldV alidator4, true);
Form1.TextBox1. value="";
Form1.TextBox2. value="";
Form1.Mode.valu e = "NewUser"
}

function LoginClick() {
if (Form1.Mode.val ue = "Broken")
ToLogin();
if (Form1.Mode.val ue = "NewUser")
ToLogin();
if (Form1.Mode.val ue = "Login")
{
if (typeof(Page_Cl ientValidate) == 'function')
{
Page_ClientVali date();
if (Page_IsValid)
Form1.submit();
}
else
{
Form1.submit()
}
}
}

function NewUserClick() {
if (Form1.Mode.val ue = "Broken")
ToNewUser();
if (Form1.Mode.val ue = "Login")
ToNewUser();
if (Form1.Mode.val ue = "NewUser")
{
if (typeof(Page_Cl ientValidate) == 'function')
{
Page_ClientVali date();
if (Page_IsValid)
Form1.submit();
}
else
{
Form1.submit()
}
}
}
</script>
</HEAD>
<body onload="ToLogin ();">
<form id="Form1" method="post" runat="server">
<P><INPUT id="Mode" type="hidden" name="Mode" runat="server">
<br>
<asp:textbox id="TextBox1"
runat="server"> </asp:textbox><as p:requiredfield validator
id="RequiredFie ldValidator1" runat="server"
ErrorMessage="R equiredFieldVal idator"
ControlToValida te="TextBox1"> </asp:requiredfie ldvalidator><BR >
<asp:textbox id="TextBox2"
runat="server"> </asp:textbox><as p:requiredfield validator
id="RequiredFie ldValidator2" runat="server"
ErrorMessage="R equiredFieldVal idator"
ControlToValida te="TextBox2"> </asp:requiredfie ldvalidator><BR >
<INPUT id="Button1" type="button" value="Button" name="Button1"
onclick="LoginC lick();"><BR>
<hr>
<BR>
<INPUT id="Button2" type="button" value="Button" name="Button2"
onclick="NewUse rClick();"><BR>
<asp:textbox id="TextBox3"
runat="server"> </asp:textbox><as p:requiredfield validator
id="RequiredFie ldValidator3" runat="server"
ErrorMessage="R equiredFieldVal idator"
ControlToValida te="TextBox3"> </asp:requiredfie ldvalidator><BR >
<asp:textbox id="TextBox4"
runat="server"> </asp:textbox><as p:requiredfield validator
id="RequiredFie ldValidator4" runat="server"
ErrorMessage="R equiredFieldVal idator"
ControlToValida te="TextBox4"> </asp:requiredfie ldvalidator>
<P></P>
<P></P>
</form>
</body>
</HTML>


Thank you, Mike
Microsoft, ASP.NET Support Professional

Microsoft highly recommends to all of our customers that they visit the
http://www.microsoft.com/protect site and perform the three straightforward
steps listed to improve your computer's security.

This posting is provided "AS IS", with no warranties, and confers no rights.

--------------------
From: "iMedia User" <xx*@us.ibm.com >
Subject: Web Form validation with 2 forms on a single page
Date: Wed, 5 Nov 2003 07:55:28 -0500
Lines: 10
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
Message-ID: <eI************ **@TK2MSFTNGP12 .phx.gbl>
Newsgroups: microsoft.publi c.dotnet.framew ork.aspnet
NNTP-Posting-Host: bi01p1.nc.us.ib m.com 129.33.49.251
Path: cpmsftngxa06.ph x.gbl!TK2MSFTNG P08.phx.gbl!TK2 MSFTNGP12.phx.g bl
Xref: cpmsftngxa06.ph x.gbl microsoft.publi c.dotnet.framew ork.aspnet:1886 79
X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet

I have a site where I want to use the Web form validators in two separate
forms on a single page. One form allows existing users to log in while the
second one allows new users to register. The problem is that if I use the
Web Form validation tags, it treats them all as one form (ie...if someone is trying to use the login form, they get an error saying that they have to
enter values in the registration form and vice-versa).

Any ideas on how to handle this?


Nov 17 '05 #2

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

Similar topics

12
2468
by: CJ | last post by:
Why won't this work? I am passing the name of the form (I have two that use this validation script) but I keep getting an error. Error reads: "document.which_form.name is null or not an object" HTML----------- Form is ----> <form action="thanks.php" method="post" name="contact_form" id="contact_form"> Name -------> <input type="text" name="name" id="name" size="25"> Button sends code -----> <input type="button" value="Submit Form"
6
3106
by: CJM | last post by:
Can somebody clarify if/how/when a simple form is submitted when the <Enter> key is pressed? As I understood it, if you have a form with a single submit button, if enter is pressed, the form should be submitted as if the button is pressed. Is this correct? Does this behaviour vary across browsers? Chris
2
2908
by: pv | last post by:
Hi everyone, I need help with following scenario, please: Users are accessing same web server from intranet (users previously authenticated in Active Dir) and from extranet (common public users). If user is from intranet, web server should recognize it and application should create additional options in controls regarding groups the user belongs to. If user is from extranet it should be logged in as anonymous and a link to login page...
7
2170
by: GeorgeAtkins | last post by:
I want to create a web-based form or page that consists of a series of formatted questions and answers. The form will resemble an existing paper form. When the form is filled in, I want the user to submit the form via e-mail and have the complete form with answers sent, not just the data. That is, the recipient should be able to open the attachment and see (and print) the complete, formatted form. It seems to me that solutions simply...
4
7267
by: jedimasta | last post by:
Good evening all, I'm a relatively new to javascript, but I've been working with ColdFusion and PHP for years so I'm not necessarily ignorant, just stuck and frustrated. Using ColdFusion I'm using an include to pull in form elements (text fields, checkboxes, etc...) multiple times on a single page. The included page does not have a form tag of it's own, but the root page has uniquely named forms for validation. Imagine it like this:
27
4752
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it may be because much of the form is populated with data from the db (lists, etc.), but when I leave...
18
5808
by: Axel Dahmen | last post by:
Hi, trying to submit an ASPX form using the key (using IE6) the page is not submitted in my web project. Trying to debug the pages' JavaScript code I noticed that there's some ASP.NET client script code being executed having a flaw: function anonymous() { if (!ValidatedTextBoxOnKeyPress(event)) { event.cancelBubble = true; if (event.stopPropagation) event.stopPropagation(); return false; } }
10
5721
by: gweasel | last post by:
What is the best way to apply a Validation Rule - or rather, where is the best place to put it? Is there an advantage to putting it on the field in the table vs setting the validation rule on the form the control is on? Basically I have a number of controls in a form that are required, and to check it I am setting the Validation Rule to "<>"IsNull" so that when the user tries to tab through/click out of a required area without entering...
13
3607
by: Andrew Falanga | last post by:
HI, Just a warning, I'm a javascript neophyte. I'm writing a function to validate the contents of a form on a web page I'm developing. Since I'm a neophyte, this function is quite simple at this time (in fact, I don't even know if it totally works, I'm still debugging). However, the first problem is that when an error is encountered, I get my alert box, I press ok and then the form is submitted and the new data is entered into the...
0
8997
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
8833
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9568
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
9335
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
9256
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
6079
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
4709
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
4881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3320
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

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.