Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

User account already exists using Customvalidator

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Dave - 22 Jun 2007 20:09 GMT
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();
   }
bruce barker - 22 Jun 2007 20:27 GMT
does your codebehind call Page.Validate?

-- bruce (sqlwork.com)

> 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
[quoted text clipped - 29 lines]
>         Conn.Close();
>     }
Dave - 22 Jun 2007 20:50 GMT
> does your codebehind call Page.Validate?
>
[quoted text clipped - 35 lines]
>
> - Show quoted text -

No.
Dave - 22 Jun 2007 21:00 GMT
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.
Dave - 22 Jun 2007 21:51 GMT
Nevermind, I gave up on the server side customvalidator and placed the
query code in the submit button handler.
Sergey Zuyev - 22 Jun 2007 22:26 GMT
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.
Signature

Programmer

> 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
[quoted text clipped - 29 lines]
>         Conn.Close();
>     }

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.