Jump to content

user's creation


narayana_anthati

Recommended Posts

Hai every one, i am facing problem on the users creation form.Before creation of validation's it's working.After that it throwing exception as "Thread has been Aborted" and the then it is showing User alredy exits and gowing to successful creation page.Plz help me.My Code Is:SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; try { cmd.CommandText = "insert into login values('" + tb1.Text + "','" + tb2.Text + "','" + ddl1.Text + "','" + tb3.Text + "','" + tb4.Text + "','" + tb5.Text + "','" + tb6.Text + "','" + tb7.Text + "','" + tb8.Text + "','" + tb9.Text + "','" + tb10.Text + "','" + ddl2.Text + "')"; conn.Open(); cmd.ExecuteNonQuery(); tb1.Text = ""; tb2.Text = ""; tb3.Text = ""; tb4.Text = ""; tb5.Text = ""; tb6.Text = ""; tb7.Text = ""; tb8.Text = ""; tb9.Text = ""; tb10.Text = ""; Response .Redirect ("registrationcompleate.aspx"); conn.Close(); } catch (Exception ex) { //Response.Write(ex.Message.ToString ()); MessageBox.Show(ex.Message.ToString()); MessageBox.Show("User Already Exists Choose Different Name", "User"); tb1.Text = ""; } }Thanks in advance;Regardsnarayana

Link to comment
Share on other sites

I do not see any prblems with your code except that if an exception does occur MessageBox.show() will fail because that is on for Windows Forms not Web Forms...you have to use javascript alert() for web messsages.

Link to comment
Share on other sites

I do not see any prblems with your code except that if an exception does occur MessageBox.show() will fail because that is on for Windows Forms not Web Forms...you have to use javascript alert() for web messsages.
Thanks for u r reply.from that no problem.But how can i use alert if the user alredy exists.plz send me.In my validation Range validator also not working>plz send me how to work with these two things.Regardsnarayana
Link to comment
Share on other sites

for example where you have

MessageBox.Show("User Already Exists Choose Different Name", "User");

you need to use

this.RegisterStartupScript("key","<script>alert('User Already Exists Choose Different Name')</script>");

Link to comment
Share on other sites

Also, you should probably close the connection before you redirect the user to another page.

Response .Redirect ("registrationcompleate.aspx");conn.Close();

Should probably be:

conn.Close();Response.Redirect ("registrationcompleate.aspx");

And watch out for SQL Injection. You might consider changing your SqlCommand text to something like this:

cmd.CommandText = "INSERT INTO Login (Username, Password) VALUES (@Username, @Password)"cmd.Parameters.AddWithValue("@Username", tb1.Text);cmd.Parameters.AddWithValue("@Password", tb2.Text);

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...