Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Remember me

Go Back   Tutorialized ForumsWeb Design & DevelopmentASP.NET

Add This Thread To:   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
Unread Tutorialized Forums Sponsor:
Old April 2nd, 2013, 01:44 PM
huggy11911 huggy11911 is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
Join Date: Apr 2013
Posts: 1 huggy11911 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 5 sec
Reputation Power: 0
Registration Not Working!

Hey everyone,

I am new to ASP.NET and I am trying to make a registration form. While I am writing the code there are no errors showing up in WebMatrix but when I run the code the error messages are showing up next to the textboxes before I even click submit. When I click submit, nothing happens. I need to have two checkboxes, one for terms of service and another for the mailing list. But I do not know how to make ASP put the value from the checkbox into a database. I also need to have the country and state field have values in a drop down list, (the values coming from a XML source) and get validated and go into a database. But as of right now I need thiss registration to work!! Any Help would be appreciated! Thanks!

@section Scripts {
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>


    Page.Title = "Register";

    // Initialize General Page Variables
    var firstName = "";
    var middleInitial = "";
    var lastName = "";
    var streetAddress = "";
    var streetAddressTwo = "";
    var city = "";
    var state = "";
    var zipCode = "";
    var country = "";
    var phoneNumber = "";
    var mobilePhone = "";
    var faxPhone = "";
    var email = "";
    var password = "";
    var confirmPassword = "";
    var mailingList = Request["mailingList"]=="off"?true:false;
    var TermsService = Request["TermsService"]=="on"?true:false;

    // Setup Validation
    Validation.RequireField("firstName", "You must specify a first name.");
    Validation.RequireField("lastName", "You must specify a last name.");
    Validation.RequireField("streetAddress", "You must specify a streetAddress.");
    Validation.RequireField("city", "You must specify a city.");
    Validation.RequireField("state", "You must specify a state.");
    Validation.RequireField("zipCode", "You must specify a zip code.");
    Validation.RequireField("country", "You must specify a country.");
    Validation.RequireField("phoneNumber", "You must specify a phone number.");
    Validation.RequireField("email", "You must specify your email address.");
    Validation.RequireField("password", "Password cannot be blank.");
        Validator.EqualsTo("password", "Passwords do not match."));
            maxLength: Int32.MaxValue,
            minLength: 6,
            errorMessage: "Password must be at least 6 characters long."));
    Validation.RequireField("TermsService", "You must accept the Terms of Service and Privacy Policy Agreement.");

    // If this is a POST request, Validate and process data
    if (IsPost) {
        firstName = Request.Form["firstName"];
        middleInitial = Request.Form["middleInitial"];
        lastName = Request.Form["lastName"];
        streetAddress = Request.Form["streetAddress"];
        streetAddressTwo = Request.Form["streetAddressTwo"];
        city = Request.Form["city"];
        state = Request.Form["state"];
        zipCode = Request.Form["zipCode"];
        country = Request.Form["country"];
        phoneNumber = Request.Form["phoneNumber"];
        mobilePhone = Request.Form["mobilePhone"];
        faxPhone = Request.Form["faxPhone"];
        email = Request.Form["email"];
        password = Request.Form["password"];
        confirmPassword = Request.Form["confirmPassword"];
        mailingList = Request["mailingList"]=="on"?true:false;
        TermsService = Request["TermsService"]=="off"?true:false;

        // Validate the user's captcha answer
       // if(Recaptcha.Validate("6Lec-t4SAAAAALBYv9CcfvQ7cj7ov9nG18td1SXB")) {
//            ModelState.AddError("recaptcha", "Captcha response was not correct. Please try again.");

        // If all information is valid, create a new account
        if (Validation.IsValid()) {
            // Insert a new user into the database
            var db = Database.Open("StarterSite");
            var ml = Database.Open("MailingList");

            // Check if the user already exists.
            var user = db.QuerySingle("SELECT Email FROM UserProfile WHERE LOWER(Email) = LOWER(15)", email);

            if (user == null) {
                // Insert email into the profile table
                db.Execute("INSERT INTO UserProfile (firstName) VALUES (1)", firstName);
                db.Execute("INSERT INTO UserProfile (middleInitial) VALUES (2)", middleInitial);
                db.Execute("INSERT INTO UserProfile (lastName) VALUES (3)", lastName);
                db.Execute("INSERT INTO UserProfile (streetAddress) VALUES (4)", streetAddress);
                db.Execute("INSERT INTO UserProfile (streetAddressTwo) VALUES (5)", streetAddressTwo);
                db.Execute("INSERT INTO UserProfile (city) VALUES (6)", city);
                db.Execute("INSERT INTO UserProfile (state) VALUES (7)", state);
                db.Execute("INSERT INTO UserProfile (zipCode) VALUES (8)", zipCode);
                db.Execute("INSERT INTO UserProfile (country) VALUES (9)", country);
                db.Execute("INSERT INTO UserProfile (phoneNumber) VALUES (10)", phoneNumber);
                db.Execute("INSERT INTO UserProfile (mobilePhone) VALUES (11)", mobilePhone);
                db.Execute("INSERT INTO UserProfile (faxPhone) VALUES (12)", faxPhone);
                db.Execute("INSERT INTO UserProfile (Email) VALUES (15)", email);
                // Create and associate a new entry in the membership database.
                //If successful, continue processing the request.

                try {
                    bool requireEmailConfirmation = !WebMail.SmtpServer.IsEmpty();
                    var token = WebSecurity.CreateAccount(email, password, requireEmailConfirmation);
                    if (requireEmailConfirmation) {
                        var hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndS  erver, UriFormat.Unescaped);
                        var confirmationUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/Confirm?confirmationCode=" + HttpUtility.UrlEncode(token));

                        to: email,
                        subject: "Please confirm your Adk Title Account",
                        body: "Your confirmation code is: " + token + ". Visit <a href=\"" + confirmationUrl + "</a> to activate your account."

                    if (requireEmailConfirmation) {
                        //Thank the user for registering and let them know an email is on its way.

                    } else {
                        //Navigate back to the homepage and exit
                        WebSecurity.Login(email, password);

                } catch
                (System.Web.Security.MembershipCreateUserException   e) {
                    ModelState.AddFormError (e.Message);

            } else {
                // User already exists
                ModelState.AddFormError("Email address is already in use.");


<!DOCTYPE html>
    <link rel="stylesheet" type="text/css" href="~/Content/sliderbutton.css">
    <link rel="stylesheet" type="text/css" href="~/Content/TermsStyle.css">
    <link rel="stylesheet" type="text/css" href="~/Content/datepicker.css">


    <form method="post">
        @* If at least one validation error exists, notify the user *@
        @Html.ValidationSummary("Account create was unsuccessful. Please correct the errors and try again.", excludeFieldErrors: true, htmlAttributes: null)

            <legend>Registration Form</legend>
                <li class="firstName">
                    <label for="firstName" @if(!ModelState.IsValidField("firstName")) {<text>class="error-label"</text>}>First Name:*</label>
                    <input type="text" id="firstName" name="firstName" value="@firstName" @Validation.For("firstName") />

                <li class="middleInitial">
                    <label for="middleInitial" @if(!ModelState.IsValidField("middleInitial")) {<text>class="error-label"</text>}>Middle Initial:</label>
                    <input type="text" id="middleInitial" name="middleInitial" value="@middleInitial" />

                <li class="lastName">
                    <label for="lastName" @if(!ModelState.IsValidField("lastName")) {<text>class="error-label"</text>}>Last Name:*</label>
                    <input type="text" id="lastName" name="lastName" value="@lastName" @Validation.For("lastName") />

                <li class="streetAddress">
                <label for="streetAddress" @if(!ModelState.IsValidField("streetAddress")) {<text>class="error-label"</text>}>Street Address:*</label>
                    <input type="text" id="streetAddress" name="streetAddress" value="@streetAddress" @Validation.For("streetAddress") />

                <li class="streetAddressTwo">
                    <label for="streetAddressTwo" @if(!ModelState.IsValidField("streetAddressTwo")){<text>class="error-label"</text>}>Second Address:</label>
                    <input type="text" id="streetAddressTwo" name="streetAddressTwo" value="@streetAddressTwo" />

                <li class="city">
                    <label for="city" @if(!ModelState.IsValidField("city")){<text>class="error-label"</text>}>City:*</label>
                    <input type="text" id="city" name="city" value="@city" @Validation.For("city") />

                <li class="state">
                    <label for="state" @if(!ModelState.IsValidField("state")) {<text>class="error-label"</text>}>State:*</label>
                    <input type="text" id="state" name="state" value="@state" @Validation.For("state") />

                <li class="zipCode">
                    <label for="zipCode" @if(!ModelState.IsValidField("zipCode")) {<text>class="error-label"</text>}>Zip Code:*</label>
                    <input type="text" id="zipCode" name="zipCode" value="@zipCode" @Validation.For("zipCode") />

                <li class="country">
                    <label for="country" @if(!ModelState.IsValidField("country")) {<text>class="error-label"</text>}>Country:*</label>
                    <input type="text" id="country" name="country" value="@country" @Validation.For("country") />

                <li class="phoneNumber">
                <label for="phoneNumber" @if(!ModelState.IsValidField("phoneNumber")){<text>class="error-label"</text>}>Home Phone:*</label>
                <input type="tel" id="phoneNumber" name="mobilePhone" value="@phoneNumber" @Validation.For("phoneNumber") />

            <li class="mobilePhone">
                <label for="mobilePhone" @if(!ModelState.IsValidField("mobilePhone")){<text>class="error-label"</text>}>Mobile Phone:</label>
                <input type="tel" id="mobilePhone" name="mobilePhone" value="@mobilePhone" />

            <li class="faxPhone">
                <label for="faxPhone" @if(!ModelState.IsValidField("faxPhone")){<text>class="error-label"</text>}>Fax Phone:</label>
                <input type="tel" id="faxPhone" name="faxPhone" value="@faxPhone" />


                <li class="email">
                    <label for="email" @if (!ModelState.IsValidField("email"))
                        Email Address:*</label>
                    <input type="email" id="email" name="email" value="@email"
                        @Validation.For("email") />
                    @* Write any email validation errors to the page *@

                <li class="password">
                    <label for="password" @if(!ModelState.IsValidField("password")){<text>class="error-label"</text>}>Password:*</label>
                    <input type="password" id="password" name="password" @Validation.For("password") />
                    @* Write any password Validation errors to the page *@

                <li class="confirm-password">
                    <label for="confirmPassword" @if(!ModelState.IsValidField("confirmPassword")){<text>class="error-label"</text>}>Confirm Password:*</label>
                    <input type="password" id="confirmPassword" name="confirmPassword" @Validation.For("confirmPassword")  />
                    @* Write any password validation errors to the page *@

                <li class="recaptcha">
                    <div class="recaptcha">
                    @*Recaptcha.GetHtml("6Lec-t4SAAAAAOlf-9lr8Uhz7sYgKJ46O5yWY_aw", theme: "white")
            <input type="submit" value="Register" />


Reply With Quote
Old May 4th, 2013, 08:47 AM
annaharris annaharris is offline
Registered User
Tutorialized Newbie (0 - 499 posts)
Join Date: Apr 2013
Posts: 22 annaharris User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 23 m 59 sec
Reputation Power: 0
Are there are any javascripts within your code ?

Reply With Quote

Viewing: Tutorialized ForumsWeb Design & DevelopmentASP.NET > Registration Not Working!

Developer Shed Advertisers and Affiliates

Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 

Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.

© 2003-2019 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap