Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7037813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:35:25+00:00 2026-05-28T01:35:25+00:00

I am working on an application which has a registration form and I have

  • 0

I am working on an application which has a registration form and I have to display to the user whether the username exists or not.
I am using asp.net mvc3 and planned to use AJAX to achieve this.

I have a form

<tr>
<td>User Name*</td>
<td><input id="UserName" name="UserName" type="text" onblur="check(this.value);"/></td>
<td id= "UName"></td>
</tr>

which calls a .js file that has the folling contents

function check(User) {
    ...
    var url = "/UserNameCheck/Index";
    url += "?User=" + User;
    xmlHttp.onreadystatechange = state_Change;
    xmlHttp.open("GET", url, true);
    xmlHttp.send(null);
}
function state_Change() {
    if (xmlhttp.readyState == 4) {// 4 = "Response loaded"

        if (xmlhttp.status == 200) {// 200 = Response Error Free               
            document.getElementById("UName").innerHTML = xmlHttp.responseText
        }
        else {
            alert("Problem retrieving XML data");
        }
    }
}

I alerted the username and I am getting the correct value that i had entered. Now, the URL is /UserNameCheck/Index where UserNameCheck is a controller and Index is a method in that.

The controller has this code.

public ActionResult Index(string User)
        {
            string UserName;
            try
            {
                Response.Cache.SetCacheability(HttpCacheability.NoCache);
                UserName = Request.QueryString["User"];
                ConnectionPackage.ConnectionClass cc = new ConnectionPackage.ConnectionClass();
                conn = cc.con;
                string sql = "Select UserName FROM UserDetails where UserName = '" + UserName + "'";
                conn.Open();
                SqlCommand cmd = new SqlCommand(sql, conn);
                cmd.CommandType = CommandType.Text;
                object p = cmd.ExecuteScalar();
                cmd.ExecuteNonQuery();
                string u = (string)p;
                if (u.Length==0 || u.Equals("NULL") || u.Equals("null")||u.Equals("Null"))
                {
                    return View();
                }

                return null;
            }
            catch (Exception ex){
            }

and the view has

 String buffer = " <table><tr><td id = 'UName' >" This user name already exists. Please select some other unser name.
 buffer = buffer + "</td></tr></table>";
 response.getWriter().println(buffer);

I also tried writing

Response.Clear();
Response.Write("UserName already exists. Please select another UserName");
Response.End();

instead of returning View.
But in both the cases, I didn’t get any message that the username exists even though I typed a user name that was already present in the database.

The connection string work for inserting into the database, so I dont think there is a problem with that. Is there a problem with the URL that I have mentioned in the js file? Or is my entire approach wrong?
I am basically from java background so dont know much about asp.net. Please do help.

Thank you very much in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:35:26+00:00Added an answer on May 28, 2026 at 1:35 am

    You’re doing alright but you could make this a whole lot easier on yourself. If you are usinng MVC3 with Razor, your app already has jQuery installed.

    1. Use the $.ajax() method to perform the calls to your controller action that checks names…

    2. Bind the $.ajax() call “unobtrusively” which means instead of on your HTML control, bind the event to your control from the jquery/javascript.

    3. Second, if you want a little fancy performance, you can bind it via the live() jquery function or keyup event, so that as you are typing the ajax call is made and you find out realtime.

    Ultimately you will end up with a lot less javascript, and your JS stuff will be cleanly separated from your markup.

    As far as your controller action is going, it looks fine for playing around and learning, but you’d want to think about either (a) putting your SQL statement as a stored procedure on the db server and calling that, or (b) writing a repository pattern class and then using LINQ to do your query work after the DB fetch.

    Another possibility would be to use Entity Framework 4.1 via NuGet to eliminate both needs. It can have a bit of a learning curve, but there’s lots of good stuff out there and your example would be fairly simple to get started with.

    Let me know if you have any specific concerns with your code and I can provide a more detailed answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on web application which has a database UserName|Password|UserType Anil|Anil|Manager ghouse|Ghouse|Admin raghu|raghu|User Now
I have a working web application which already has a login and registration system.
I’m working on an application which has been designed using n-tire application architecture .The
Well, simple question. I'm working with VS2008 on an ASP.NET web application which has
I am working in Visual Studio 2008 on an ASP.NET application, which has been
I am working on an ASP.NET MVC application which has a model for a
I'm working on application which has workflow like this: 1.parsing home page (using HttpURLConnection,
I am currently working on an Android application which has an order form. I
i have an application which has 3X4 matrix of images using arrow key(up,right,top,bottom) i
I'm working in mid-size .NET application which has a very very bad if not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.