當有人填寫我的註冊表單並輸入用戶名時,它會刷新頁面並顯示「用戶名已被佔用,選擇另一個」。如何在使用用戶名時取消發送數據
但該人填寫的所有數據都已刪除。
如何取消用戶名,讓用戶可以更改它?
protected string msg = "";
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
string FirstName = Request.Form["FirstName"];
string LastName = Request.Form["LastName"];
string PhoneNumber = Request.Form["PhoneNumber"];
string Prefix = Request.Form["Prefix"];
PhoneNumber = Prefix + PhoneNumber;
int BirthYear = int.Parse(Request.Form["BirthYear"]);
string Email = Request.Form["Email"];
string UserName = Request.Form["UserName"];
string Password = Request.Form["Password"];
string gender = Request.Form["gender"];
string dbPath = this.MapPath("App_Data/Database.mdf");
DAL dal = new DAL(dbPath);
UtilityUser uu = new UtilityUser(dal);
if (uu.Exist(UserName))
{
msg = "שם המשתמש שבחרת תפוס"; **//username is taken**
}
else
{
uu.Register(FirstName, LastName, PhoneNumber, BirthYear, Email, UserName, Password, gender);
msg = "נרשמת בהצלחה!"; **// Register succeed**
}
}
}
這是檢查用戶名的形式:您需要使用Ajax這個功能
var UserName = aspnetForm.UserName.value;
if (UserName.length < 6) {
document.getElementById("labelUserName").innerHTML = '<img src=\'images/X.png\'>'; //**X icon**
Fields += "שם משתמש - שדה זה חייב להכיל בין 6 ל־12 תווים\n";
correct = false;
}
else {
document.getElementById("labelUserName").innerHTML = '<img src=\'images/V.png\'>'; //**V icon**
}
使用ajax檢查用戶名 –
你能幫我嗎?如何使用Ajax或什麼? – Ran
@Ran檢查我的答案,讓我知道你在用什麼服務器端技術,所以我可以幫助 – Alex