Solved

Validating Login control fields

Posted on 2008-06-20
5
173 Views
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!

   allanmark
0
Comment
Question by:allanmark
  • 2
  • 2
5 Comments
 
LVL 16

Expert Comment

by:burakiewicz
ID: 21832708
Login1 == name of your login control
protected void btnForgotPassW_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Login1.UserName))
            {
                //no username
            }
            else
            {
                //has username
            }
        }
0
 
LVL 7

Accepted Solution

by:
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:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.login.layouttemplate.aspx

HTH,
Karl
0
 

Author Comment

by:allanmark
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
0
 
LVL 7

Assisted Solution

by:kGenius
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 asp.net can help you out:
http://forums.asp.net/p/1058284/1512529.aspx
0
 

Author Closing Comment

by:allanmark
ID: 31469169
Excellent answers!!  Many thanks!!!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
.net VBA word safemode 1 24
Binding a check box in an Asp.net DataGrid 4 27
Set form below another form 3 26
Close word object 13 24
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

759 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