无效的回发或回调参数。点击按钮

时间:2014-01-16 13:17:36

标签: c# asp.net webforms

我的asp.net网页上有以下代码片段。

<div id="descDiv" style="display:none;">
<form>
                            <asp:TextBox ID="inputDesc" Height="200px" Width="100%" runat="server" TextMode="MultiLine" placeholder="Enter any details you know about this city" required="required"></asp:TextBox>
                            <input type="button" Class="cancel" value="Cancel" OnClick="hideInput('descDiv');" /><asp:Button ID="Submit_Desc" CssClass="submit" runat="server" Text="Submit" OnClick="Submit_Desc_Click" />
                          </form>
                        </div>

当我点击提交按钮时,我收到此错误:

  Invalid postback or callback argument. Event validation is enabled using 
  <pages enableEventValidation="true"/> in configuration or 
  <%@ Page EnableEventValidation="true" %> in a page.  
  For security purposes, this feature verifies that arguments to postback or 
  callback events originate from the server control that originally rendered them.  
  If the data is valid and expected, use the
  ClientScriptManager.RegisterForEventValidation method in order to register the
  postback or callback data for validation.

此表单包含在另一个具有'runat'属性的主窗体中。我该怎么做才能解决这个问题?

编辑:

以下是重现问题的最短代码:

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication1.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div id="descDiv">
            <form>
                 <asp:TextBox ID="inputDesc" Height="200px" Width="100%" runat="server" TextMode="MultiLine" placeholder="Enter any details you know about this city" required="required"></asp:TextBox>
                  <input type="button" class="cancel" value="Cancel" onclick="hideInput('descDiv');" />
                  <asp:Button ID="Submit_Desc" CssClass="submit" runat="server" Text="Submit" OnClick="Submit_Desc_Click"/>
             </form>
         </div>
    </div>
        <form>
            <asp:TextBox ID="TextBox1" Height="200px" Width="100%" runat="server" TextMode="MultiLine" placeholder="Enter any details you know about this city" required="required"></asp:TextBox>
            <input type="button" class="cancel" value="Cancel" onclick="hideInput('descDiv');" />
             <asp:Button ID="Button1" CssClass="submit" runat="server" Text="Submit" OnClick="Submit_Desc_Click"/>
        </form>
    </form>
</body>
</html>

1 个答案:

答案 0 :(得分:4)

您的页面上不能有两个表单,请删除div下面的表单标记。要保留的那个必须是runat =“server”,因为它是.net页面。

你可以做的是使用.net按钮并处理他们从代码背后做的任何事情

<form id="form1" runat="server">
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
     <asp:Button ID="Button2" runat="server" Text="Button" OnClick="Button2_Click" />
</form>

  protected void Button1_Click(object sender, EventArgs e)
{

    // do something with button 1

}
protected void Button2_Click(object sender, EventArgs e)
{
    // do something with button 2
}