我正在使用ASP.NET Web应用程序,我有一个注册表单,每当我尝试键入用户Username
时,此错误都会显示在浏览器中!
无效的回发或回调参数。事件验证已启用 在配置中使用或<%@ Page EnableEventValidation =“true”%>在一个页面中。为了安全 目的,此功能验证回发或回调的参数 事件源自最初呈现的服务器控件 他们。如果数据有效且预期,请使用 ClientScriptManager.RegisterForEventValidation方法 注册回发或回调数据以进行验证。
我试图在if(!IsPostBack){///Your Code.... }
中添加Page_Load
,但它无效!我再次在EnableEventValidation="false"
中尝试了web.config
它没有用!请帮忙吗?
注册表格代码:
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"); }
}
和我的web.config
代码:
<pages validateRequest="true">
<namespaces>
<add namespace="System.Web.Optimization" />
<add namespace="Microsoft.AspNet.Identity" />
</namespaces>
<controls>
<add assembly="Microsoft.AspNet.Web.Optimization.WebForms" namespace="Microsoft.AspNet.Web.Optimization.WebForms" tagPrefix="webopt" />
</controls>
</pages>
更新
<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>
</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>
</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>
</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>
</td>
</tr>
<tr>
<td class="auto-style13"> </td>
<td class="auto-style10">
<asp:Button ID="Button6" runat="server" OnClick="Button6_Click" Text="done" ForeColor="#990033" />
</td>
<td class="auto-style11"> </td>
<td> </td>
</tr>
</table>