点击ASP.net Gridview的标题导致回发。怎么阻止这个?

时间:2016-02-25 07:40:36

标签: c# asp.net gridview

我正在使用ASP.net建立一个网站。那里有一个gridview。 问题是,当我点击gridview的标题时,它会导致回发页面。不知道如何阻止这一点。这是代码

   <asp:GridView ID="gridEmployee" Width="100%" RowStyle-Height="15" HeaderStyle-BackColor="#3AC0F2"
                HeaderStyle-ForeColor="White" RowStyle-BackColor="Black" RowStyle-ForeColor="#3A3A3A"
                AutoGenerateColumns="False" BorderWidth="1px" OnRowCreated="gridEmployee_RowCreated" OnSelectedIndexChanging="gridEmployee_SelectedIndexChanging"
                ClientIDMode="Static" ShowHeaderWhenEmpty="True" DataKeyNames="employee_master_id_pk"
                AllowPaging="True" PageSize="20" runat="server" EnableViewState="false" OnPageIndexChanging="gridEmployee_PageIndexChanging">
                <Columns>
                    <asp:TemplateField>
                        <ItemTemplate>
                            <asp:Image runat="server" ImageUrl='<%#string.Format("/images/profile_full/{0}",Eval("image_url")) %>' Width="50px" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField HeaderText="NAME" ReadOnly="true" DataField="call_name">
                        <HeaderStyle Width="70%" />
                    </asp:BoundField>
                    <asp:BoundField HeaderText="MOBILE" ReadOnly="true" DataField="mobile_no">
                        <HeaderStyle Width="30%" />
                    </asp:BoundField>
                    <asp:CommandField ShowSelectButton="true" ItemStyle-CssClass="hiddencol" HeaderStyle-CssClass="hiddencol" />
                </Columns>
                <SelectedRowStyle BackColor="#0AA6FF" Font-Bold="True" Font-Italic="true" ForeColor="White" />
                <HeaderStyle BackColor="#199e38" ForeColor="White" Height="20px" Font-Size="Medium"></HeaderStyle>
                <RowStyle BackColor="#f6f7f9" ForeColor="Black" Height="20px" HorizontalAlign="Left" />
            </asp:GridView>

以下是显示

的错误消息
  

System.Web.HttpUnhandledException(0x80004005):类型异常   &#39; System.Web.HttpUnhandledException&#39;被扔了。 ---&GT;   System.ArgumentException:无效的回发或回调参数。   使用配置或&lt;%@ Page启用事件验证   EnableEventValidation =&#34;真&#34; %GT;在一个页面中。出于安全考虑,   此功能验证回发或回调事件的参数   源自最初呈现它们的服务器控件。如果   数据有效且预期,使用   ClientScriptManager.RegisterForEventValidation方法   注册回发或回调数据以进行验证。在   System.Web.UI.ClientScriptManager.ValidateEvent(String uniqueId,   System.Web.UI.Control.ValidateEvent(String   uniqueID,String eventArgument)at   System.Web.UI.WebControls.GridView.RaisePostBackEvent(字符串   eventArgument)at   System.Web.UI.WebControls.GridView.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(字符串   eventArgument)at   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler   sourceControl,String eventArgument)at   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
  在System.Web.UI.Page.ProcessRequestMain(布尔值   includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)
  在System.Web.UI.Page.HandleError(Exception e)at   System.Web.UI.Page.ProcessRequestMain(布尔   includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)
  在System.Web.UI.Page.ProcessRequest(布尔值   includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)
  在System.Web.UI.Page.ProcessRequest()处   System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
  在System.Web.UI.Page.ProcessRequest(HttpContext context)处   ASP.private_task_aspx.ProcessRequest(HttpContext context)中   c:\ Users \ testl \ AppData \ Local \ Temp \ Temporary ASP.NET   Files \ root \ cc51fe2f \ b39cd5d2 \ App_Web_wtae1pov.4.cs:第0行   System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()   在System.Web.HttpApplication.ExecuteStep(IExecutionStep步骤,   布尔和放大器; completedSynchronously)

1 个答案:

答案 0 :(得分:0)

问题是关于排序与否。

如果您希望GridView no可以排序,则必须设置

<asp:GridView ID="gridEmployee"  AllowSorting="false"

如果你想允许排序但没有完整的回发,你必须在GridView周围添加一个UpdatePanel

<asp:UpdatePanel>
    <ContentTemplate>
       <asp:GridView ID="gridEmployee"