首页 新闻 会员 周边 捐助

关于ClientScriptManager.RegisterForEventValidation

0
[已解决问题] 解决于 2012-03-19 09:09

  就是在GridView 中写个分布如下:

<PagerTemplate>    
               <br />      
                 <asp:Label ID="lblPage" runat="server" Text='<%# "第" + (((GridView)Container.NamingContainer).PageIndex + 1)  + "页/共" + (((GridView)Container.NamingContainer).PageCount) + "页" %> '></asp:Label> 
                        <asp:LinkButton ID="lbnFirst" runat="Server" Text="首页"  Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="First" ></asp:LinkButton>   
                            <asp:LinkButton ID="lbnPrev" runat="server" Text="上一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>' CommandName="Page" CommandArgument="Prev"  ></asp:LinkButton>  
                                 <asp:LinkButton ID="lbnNext" runat="Server" Text="下一页" Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Next" ></asp:LinkButton>  
                                       <asp:LinkButton ID="lbnLast" runat="Server" Text="尾页"   Enabled='<%# ((GridView)Container.NamingContainer).PageIndex != (((GridView)Container.NamingContainer).PageCount - 1) %>' CommandName="Page" CommandArgument="Last" ></asp:LinkButton>  
                                            到第<asp:TextBox runat="server" ID="inPageNum"></asp:TextBox>页 <asp:Button ID="Button1" CommandName="go" CommandArgument="goto" Text="GO" runat="server" />         <br /> 
                                           
               </PagerTemplate>

 

 

事件中: protected void grdServer_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        try
        {
            //grdServer.PageIndex = e.NewPageIndex-1;
            grdServerBangding();
            //TextBox tb = (TextBox)grdServer.BottomPagerRow.FindControl("inPageNum");
            //tb.Text = (grdServer.PageIndex + 1).ToString();
        }
        catch
        {
        }
      
    }

protected void grdServer_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "go")
        {

            try
            {
                TextBox tb = (TextBox)grdServer.BottomPagerRow.FindControl("inPageNum");
                int num = Int32.Parse(tb.Text);
                GridViewPageEventArgs ea = new GridViewPageEventArgs(num - 1);
                grdServer_PageIndexChanging(null, ea);
                //grdServer.PageIndex = num;
            }
            catch
            {
            }
        }
        if (e.CommandArgument == "First")
        {
            grdServer.PageIndex = 0;
        }
        else if (e.CommandArgument == "Next")
        {
            if (grdServer.PageIndex < grdServer.PageCount - 1)
            {
                grdServer.PageIndex += 1;
            }
        }
        else if (e.CommandArgument == "Prev")
        {
            if (grdServer.PageIndex >= 1)
            {
                grdServer.PageIndex -= 1;
            }
        }
        else if (e.CommandArgument == "Last")
        {
            grdServer.PageIndex = grdServer.PageCount-1;
        }

    }

 

 

就是老报说什么

回发或回调参数无效。在配置中使用 <pages enableEventValidation="true"/> 或在页面中使用 <%@ Page EnableEventValidation="true" %> 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。

浩凡儿的主页 浩凡儿 | 初学一级 | 园豆:147
提问于:2012-01-02 15:06
< >
分享
最佳答案
0

把enableEventValidation属性设置为false就可以了

Eugene Wang | 菜鸟二级 |园豆:439 | 2012-01-05 13:21
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册