User account already exists using Customvalidator

D

Dave

I've suprisingly not been able to find examples on this. I'm creating
a user account setup page, and the validators work fine on all the
other fields. But now I'm creating a customvalidator (for the first
time) and it is not doing anything. The page needs to see if a
username already exists. Am I doing this right?


<asp:textbox TabIndex="1" ID="tLogin" MaxLength="40" runat="server" />
<asp:customvalidator id="Customvalidator1" runat="server"
EnableClientScript="False" Font-Bold="True" ErrorMessage="Username
already exists." ControlToValidate="tLogin"
OnServerValidate="CheckUser" Display="Dynamic"/>



void CheckUser(object source,
System.Web.UI.WebControls.ServerValidateEventArgs args)
{
TextBox b;
b = fLogin.FindControl("tLogin") as TextBox;
String lg = b.Text;
String strConn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA
SOURCE=" + Server.MapPath("info.mdb") + ";";
OleDbConnection Conn = new OleDbConnection(strConn);
Conn.Open();
String strSQL = "SELECT * FROM Customers WHERE Login = '" + lg
+ "'";
OleDbCommand Cmd = new OleDbCommand(strSQL, Conn);
OleDbDataReader Dr =
Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection);
if (Dr.HasRows)
{
args.IsValid = false;
} else args.IsValid = true;
Conn.Close();
}
 
D

Dave

Actually even when I set the custom event handler to just return
false, it still does not kick in with the error message. Why isn't it
doing anything? Any help would be appreciated.
 
D

Dave

Nevermind, I gave up on the server side customvalidator and placed the
query code in the submit button handler.
 
G

Guest

Custom Validator ServerValidate event will not fire if text is empty. By
default ValidateEmptyText property is set to False. Set it to true and try
again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top