Validating Login control fields

Posted on 2008-06-20
Last Modified: 2013-12-16
Greetings all

I have a Login control on a page and a button, called "btnForgotPassW. When the user clicks the ForgottenPassW button, I want to ensure that he has at leat entered his userame in the appropriate field.

How do I do this?

In advance, thanks!

Question by:allanmark
  • 2
  • 2
LVL 16

Expert Comment

ID: 21832708
Login1 == name of your login control
protected void btnForgotPassW_Click(object sender, EventArgs e)
            if (string.IsNullOrEmpty(Login1.UserName))
                //no username
                //has username

Accepted Solution

kGenius earned 250 total points
ID: 21832731
You can use the LayoutTemplate in your login control. Then add the RequiredFieldValidator for your username textbox.
This method is discribed in:


Author Comment

ID: 21833779
Looks good!

How do I only validate the username field on the Forgot button click?

The username and password field valdiators are assigned to Login1. I could change the password fieldvalidator's group to Login2 and then set the Forgot button to Login1 -- problem  -- as far as I can tell, you can only have one validation group attached to a control, so the LogIn button would ahve to be Login11 or Login2, but NOT both

Assisted Solution

kGenius earned 250 total points
ID: 21835054
You can use a javascript that checks the value of the input field username.
When empty the form may not be submitted.
I think this thread on can help you out:

Author Closing Comment

ID: 31469169
Excellent answers!!  Many thanks!!!

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Sending a Secure fax is easy with eFax Corporate ( First, just open a new email message. In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now