gpt4 book ai didi

c# - 回发或回调参数无效。单击按钮

转载 作者:太空宇宙 更新时间:2023-11-03 21:37:07 24 4
gpt4 key购买 nike

我的 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>

最佳答案

您的页面上不能有两个表单,请删除您的 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
}

关于c# - 回发或回调参数无效。单击按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21162909/

24 4 0