473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

User account already exists using Customvalidator

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.Clos eConnection);
if (Dr.HasRows)
{
args.IsValid = false;
} else args.IsValid = true;
Conn.Close();
}

Jun 22 '07 #1
5 3167
does your codebehind call Page.Validate?
-- bruce (sqlwork.com)

Dave wrote:
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.Clos eConnection);
if (Dr.HasRows)
{
args.IsValid = false;
} else args.IsValid = true;
Conn.Close();
}
Jun 22 '07 #2
On Jun 22, 2:27 pm, bruce barker <nos...@nospam.comwrote:
does your codebehind call Page.Validate?

-- bruce (sqlwork.com)

Dave wrote:
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.Clos eConnection);
if (Dr.HasRows)
{
args.IsValid = false;
} else args.IsValid = true;
Conn.Close();
}- Hide quoted text -

- Show quoted text -
No.

Jun 22 '07 #3
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.

Jun 22 '07 #4
Nevermind, I gave up on the server side customvalidator and placed the
query code in the submit button handler.

Jun 22 '07 #5
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.
--
Programmer
"Dave" wrote:
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.Clos eConnection);
if (Dr.HasRows)
{
args.IsValid = false;
} else args.IsValid = true;
Conn.Close();
}

Jun 22 '07 #6

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

Similar topics

0
by: Wayne Gibson | last post by:
Hi all, Please ignore the other post.. The cat jumped on the machine and sent it before I could stop it!! Was wondering if anybody has expericence this problem.. I am writting an application...
2
by: Sandman | last post by:
Just looking for suggestion on how to do this in my Web application. The goal is to keep track of what a user has and hasn't read and present him or her with new material I am currently doing...
11
by: Marcelo López | last post by:
I need to create a folder in the file system owned by an special user created by my application. The idea is that only my app will have permissions to delete and create files on that folder. My...
10
by: Rigs | last post by:
Hi, I have a textbox with a Custom Validator that utilizes the OnServerValidate method for that textbox. This works fine, however the method only executes when data exists in that textbox after...
3
by: Brent Burkart | last post by:
I have a web application which consist of a huge form with many requiredfieldvalidators. Before the user submits, I want to prompt the user to print. I have tried to do this with the help of a...
5
by: Roshan | last post by:
Hi, Given a name, I want to be able to detect if a user or a group account exists with that name on a system and know if its a user or a group. My search yielded the "LookupAccountName" Win32...
0
by: Eniac | last post by:
Hi, I've been working on a custom user control that needs to be modified and the validation is causing me headaches. The control used to generate a table of 4 rows x 7 columns to display all...
1
by: Carlettus | last post by:
Dear All, sorry but I'm not sure if this is the right place to post my problem. I was using the following asp code to create users in Active Directory. Suddenly, and I don't know the reason, users...
3
by: shapper | last post by:
Hello, On my web site I have a property, Visitor, which is available for Anonymous users: public class Visitor { public CultureInfo Culture { get; set; } public List<GuidPolls { get; set;...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.