![]() |
Login control with username dropdown not working
Hi,
I need a dropdown list of usernames in login control to authenticate users. I followed your webpage http://imar.spaanjaars.com/409/chang...-list-of-users However, for some reason, the login control still seems to be expecting a username entry rather than getting the selected value from dropdown. I also tried to display (using response.write) the selected dropdown value in logingIn event...but no message appears. Here is my code. Please help! (BTW I am using a SQLdatasource to populate the dropdown with usernames instead of objectdatasource.) Code:
<%@ Page Title="Login" Language="C#" MasterPageFile="~/Welcome.Master" AutoEventWireup="true"using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Configuration; using System.Data; using System.Web.Security; namespace devhub { public partial class Login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { Boolean bauthenticated = false; bauthenticated = isValidUser(Login1.UserName, Login1.Password); if (bauthenticated) { e.Authenticated = true; } else { e.Authenticated = false; } } private Boolean isValidUser(string username, string password) { //Validate username and password SqlConnection conn; string connectionString = ConfigurationManager.ConnectionStrings["HUBConnectionString"].ConnectionString; conn = new SqlConnection(connectionString); SqlCommand comm; comm = new SqlCommand("SELECT Full_Name,Password,Position FROM REDMs WHERE Full_Name=@Username AND Password=@Password", conn); comm.Parameters.AddWithValue("@Username", username); comm.Parameters.AddWithValue("@Password", password); DataTable dt = new DataTable(); SqlDataAdapter da = new SqlDataAdapter(comm); conn.Open(); da.Fill(dt); conn.Close(); if (dt.Rows.Count == 0) { dt.Dispose(); return false; } //FormsAuthentication.RedirectFromLoginPage(Login1.U serName, false); return true; } protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e) { Login1.UserName = ((DropDownList) Login1.FindControl("ddlUsername")).SelectedValue; Response.Write(""+Login1.UserName); } } } |
you should check it again step by step because in my view you did well but if the result not shown you can recheck with highly focus then you got the result.
fort st john |
| All times are GMT -4. The time now is 11:20 PM. |
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.