1

这是我的 DataGridView

<asp:GridView ID="gvPredstave" runat="server" CssClass="gridview" 
        AlternatingRowStyle-CssClass="even" AutoGenerateColumns="True">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID="btnRezervisi" runat="server" Text="Rezervisi" onclick="Button1_Click" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>

这是我在 GridView 中单击按钮的代码

protected void Button1_Click(object sender, EventArgs e)
    {
        Response.Redirect("AktivneRezervacije.aspx?korisnicko_ime=" + korisnicko_ime);
        conn.Close();
    }

当我单击按钮时,我在浏览器中收到此错误:

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.

有谁知道发生这种情况的原因。我尝试了 EnableEventValidation="false" 但它不起作用。

4

2 回答 2

1

我使用您的 gridView 重新创建了错误并将其绑定。答案在于Page_Load事件。如果你有这样的:

protected void Page_Load(object sender, EventArgs e)
{
    bindGridView(); //code to bind the GridView
}

你会得到例外。将其更改为:

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        bindGridView();
    }
}

你不应该再收到错误了。

于 2013-08-13T17:23:40.753 回答
0

如果页面处于回发状态,您有两种方法可以使其工作,或者在您的 gridview 上添加回发事件或控制页面加载。

关于conn.close(); 将连接重定向到另一个页面后首先关闭连接。

快乐编码。

于 2013-08-14T01:34:47.823 回答