如何停止加载注册表中的整个 HTML 页面? - ASP.NET

How to stop loading the whole HTML page in registration form ? - ASP.NET

我正在使用 ASP.NET 网络应用程序。我已经完成了注册表,但是每当用户键入 UsernameEmail 时,它将加载整个 first_home 页面!我怎样才能停止加载整个页面?我在数据库中为 UsernameEmail 设置了一个约束以避免重复。

HTML代码:

<table align="left" class="auto-style8" dir="rtl">                             
    <tr>
        <td class="auto-style13">username </td>
        <td class="auto-style10">
            <br />
            <asp:TextBox ID="TextBoxUsername" runat="server" AutoPostBack="true"  Height="25px" Width="223px" ForeColor="#990033" OnTextChanged="TextBoxUsername_TextChanged"></asp:TextBox>
            <br />
        </td>
        <td class="auto-style11">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBoxUsername" ErrorMessage="write username"></asp:RequiredFieldValidator>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="auto-style13">password</td>
        <td class="auto-style10">
            <br />
            <asp:TextBox ID="TextBoxPassword" runat="server" Height="25px" Width="223px" ForeColor="#990033" TextMode="Password" OnTextChanged="TextBoxPassword_TextChanged"></asp:TextBox>
            <br />
        </td>
        <td class="auto-style11">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="TextBoxPassword" ErrorMessage="must write the password"></asp:RequiredFieldValidator>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="auto-style13">confirm password </td>
        <td class="auto-style10">
            <br />
            <asp:TextBox ID="TextBoxCPassword" runat="server" Height="25px" Width="223px" ForeColor="#990033" TextMode="Password" OnTextChanged="TextBoxCPassword_TextChanged"></asp:TextBox>
            <br />
        </td>
        <td class="auto-style11">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" ControlToValidate="TextBoxCPassword" ErrorMessage="must write the password"></asp:RequiredFieldValidator>
            <br />
            <asp:CompareValidator ID="CompareValidator1" runat="server" ControlToCompare="TextBoxPassword" ControlToValidate="TextBoxCPassword" ErrorMessage="wrong password"></asp:CompareValidator>
        </td>
        <td>
            &nbsp;</td>
    </tr>
    <tr>
        <td class="auto-style13">email</td>
        <td class="auto-style10">
            <br />
            <asp:TextBox ID="TextBoxEmail" runat="server" AutoPostBack="true"  Height="25px" Width="223px" ForeColor="#990033" TextMode="Email" OnTextChanged="TextBoxEmail_TextChanged"></asp:TextBox>
            <br />
        </td>
        <td class="auto-style11">
            <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" ControlToValidate="TextBoxEmail" ErrorMessage="must write email"></asp:RequiredFieldValidator>
            <br />
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="TextBoxEmail" ErrorMessage="the email no valid" ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
        </td>
        <td>
            &nbsp;</td>
    </tr>
        <tr>
        <td class="auto-style13">&nbsp;</td>
        <td class="auto-style10">
            <asp:Button ID="Button6" runat="server" OnClick="Button6_Click" Text="done" ForeColor="#990033" />
        </td>
        <td class="auto-style11">&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
</table> 

first_home.aspx.cs代码:

public partial class First_home : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString);
            conn.Open();
            // check if the username is taken before 
            string checkuser = "Select count(*) from Users where Username='" + TextBoxUsername.Text + "'";
            SqlCommand com = new SqlCommand(checkuser, conn);
            int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
            if (temp == 1)
            { Response.Write("error"); }
            conn.Close();
        }
    }
    protected void Button6_Click(object sender, EventArgs e)
    {
        try
        {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString);
            conn.Open();
            string insertQuery = "insert into Users (Username,Password,Email) values (@username, @password, @email)";
            SqlCommand com = new SqlCommand(insertQuery, conn);

            com.Parameters.AddWithValue("@username", TextBoxUsername.Text);
            com.Parameters.AddWithValue("@password", TextBoxPassword.Text);
            com.Parameters.AddWithValue("@email", TextBoxEmail.Text);

            com.ExecuteNonQuery();
            conn.Close();
            Response.Redirect("Seller_Registration.aspx");
        }
        catch (Exception ex)
        { Response.Write("error "); }
    }

还有数据库 CONSTRAINT :

CONSTRAINT [AK_Users_Email] UNIQUE NONCLUSTERED ([Email] ASC),
CONSTRAINT [AK_Users_Username] UNIQUE NONCLUSTERED ([Username] ASC),

从这两个控件中删除 AutoPostBack="true" 属性。

每当您输入内容并从该控件中聚焦时,这两个控件就会导致 PostBack。这就是整个页面加载背后的原因。