无效的回发或回调参数。这有什么code中的问题? [英] Invalid postback or callback argument. what is the issue with this code?

查看:166
本文介绍了无效的回发或回调参数。这有什么code中的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这样的GridView和我不知道什么是它里面的按钮的问题。
我有这样的ASP code:

I have this gridview and i don't know what is the problem with the buttons inside it. I have this asp code:

<asp:GridView ID="gvList" runat="server">
            <Columns>
                <asp:TemplateField HeaderText="User Name" HeaderStyle-ForeColor="Black"  HeaderStyle-Font-Bold="true">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lblUsername" Text='<%# Eval("cUserName") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Dept User" HeaderStyle-ForeColor="Black"  HeaderStyle-Font-Bold="true">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lblDept" Text='<%#  iif(Eval("lDeptUser"),"Yes","No")  %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Actions" HeaderStyle-ForeColor="black" HeaderStyle-Font-Bold="true">
                    <ItemTemplate>
                        <asp:Button  ID="btnedit" runat="server" Text="Edit" />
                        <asp:Button ID="btnDelete" OnClick="DeleteRow" runat="server" Text="Delete" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
            </asp:GridView>

当我preSS删除或编辑任何行它使我的错误! 无效的回发或回调参数。

这是在vb.net我的服务器端code:

This is my server side code in vb.net:

Public Function GetList() As DataTable
    Dim Query As String = "Select cUserName,lDeptUser FROM Intranet.dbo.Gn_ISCoordinators"
    Dim dt As DataTable = New DataTable()
    Using adapter = New SqlDataAdapter(Query, ConfigurationManager.ConnectionStrings("IntranetConnectionString").ConnectionString)
        adapter.Fill(dt)
        gvList.DataSource = dt
        gvList.DataBind()
        Return dt
    End Using

End Function

Public Function DelRow() As DataTable

    Dim strusername As String = CType(gvList.FindControl("lblUsername"), Label).Text.Trim()

    Dim Query As String = "Delete FROM Intranet.dbo.Gn_ISCoordinators where cUserName='" & strusername & "'"
    Dim dt As DataTable = New DataTable()
    Using Adapter = New SqlDataAdapter(Query, ConfigurationManager.ConnectionStrings("IntranetConnectionString").ConnectionString)
        Adapter.Fill(dt)
        Return dt
    End Using

End Function

Protected Sub DeleteRow(ByVal sender As Object, ByVal e As System.EventArgs)
    DelRow()
End Sub

Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
    GetList()

End Sub

Protected Sub gv(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvList.RowDataBound
    e.Row.Cells(3).Visible = False
    e.Row.Cells(4).Visible = False


End Sub

End Class

我认为,从客户端的。请帮我解决这个问题。
顺便说一句,我不使用任何ajaxtoolkit到现在和 EnableEventValidation =真正的中的一页,也为在web.config

I think that its from the client side. Please help me with this problem. btw i am not using any ajaxtoolkit till now and the EnableEventValidation="true" in the page as well as the web.config

有什么问题及其解决方案,请帮助我。

What is the problem and its solution, please help me.

先谢谢了。

推荐答案

首先,我想包在code 的Page_Load

First i would wrap the code in Page_Load:

If Not IsPostBack Then GetList()

所以,你只是想在数据绑定第一次加载,而不是回发电网。这是国家将通过 ViewwState 默认情况下进行维护。

DeleteRow 下一个问题,你正在努力寻找通过的FindControl 在<$ C $标签C> GridView控件。但 NamingContainer 它是 GridViewRow 因为 GridView控件包含多行(和标签)不只是一个。

The next problem in DeleteRow, you are trying to find the label via FindControl on the GridView. But the NamingContainer of it is the GridViewRow since a GridView contains multiple rows(and labels) not just one.

所以,你必须首先获得参考一行。只需使用按钮 NamingContainer

So you have to get the reference to the row first. Just use the NamingContainer of the Button:

Dim btn = DirectCast(sender, Button)
Dim row = DirectCast(btn.NamingContainer, GridViewRow)
Dim lblUsername = DirectCast(row.FindControl("lblUsername"), Label)
' ... '

这篇关于无效的回发或回调参数。这有什么code中的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆