2009-03-24 4 views
1

다음 코드에서 :ASP.NET :의 GridView pageEventValidation 문제

EnquiryList.ascx :

<%@ Control Language="C#" AutoEventWireup="true" CodeFile="EnquiryList.ascx.cs" Inherits="includes_EnquiryList"%> 
<div class="EnquiryForm" runat="server"> 

    <asp:GridView ID="gridMain" 
     runat="server" 
     PageSize="20" 
     Width="390" 
     GridLines="None" 
     CssClass="gridview" 
     AllowPaging="True" 
     AllowSorting="True" 
     CellPadding="0" 
     AutoGenerateColumns="False" 
     OnPageIndexChanging="gridMain_PageIndexChanging" 
     OnRowCommand="gridMain_RowCommand" 
     DataSourceID="ldsGridMain"> 

     <Columns> 

      <asp:TemplateField> 
       <ItemTemplate> 

        <%# Eval("Id") %> 
        <asp:Button Text="Bekräfta" ID="apa" runat="server" CommandArgument='<%# Eval("Id") %>' CommandName="Buy" class="enquiryBtn"/> 

       </ItemTemplate> 
      </asp:TemplateField> 


     </Columns> 

    </asp:GridView> 

    <asp:LinqDataSource ID="ldsGridMain" runat="server" OnSelecting="ldsGridMain_Selecting" OnSelected="ldsGridMain_Selected"/> 

</div> 

EnquiryList.ascx.cs : SupplierInbox.aspx.cs에서

using System; 
using System.Web.UI.WebControls; 
using System.Web.UI; 
using Offerta.Presentation; 
using System.Collections; 
using System.Collections.Generic; 
using System.Linq; 

public partial class includes_EnquiryList : System.Web.UI.UserControl 
{ 

    protected Boolean IsAuthenticatedSupplier { get; set; } 

    protected Boolean ShowSimilarEnquiriesLink { get; set; } 

    protected int totalRows = 0; 

    protected LinqDataSourceSelectEventArgs selectArgs; 

    protected Supplier supplier; 

    protected IQueryable<Enquiry> enquiries; 

    protected string errorMessage; 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     IsAuthenticatedSupplier = false; 
     Auth auth = new Auth(); 
     if (auth.IsAuthenticated) 
     { 
      IsAuthenticatedSupplier = auth.ClientTypeId == ClientMethods.CLIENT_TYPE_SUPPLIER; 
      if (IsAuthenticatedSupplier) 
      { 
       supplier = (Supplier)auth.Client; 
      } 
     } 
    } 


    public void Bind(IQueryable<Enquiry> enquiries) 
    { 
     this.enquiries = enquiries; 
     gridMain.DataBind(); 
    } 

    protected void ldsGridMain_Selecting(object sender, LinqDataSourceSelectEventArgs e) 
    { 
     selectArgs = e; 
     e.Result = (new EnquiryListController()).List(enquiries, supplier); 
    } 

    protected void ldsGridMain_Selected(object sender, LinqDataSourceStatusEventArgs e) 
    { 
     totalRows = selectArgs.Arguments.TotalRowCount; 
    } 

    protected void gridMain_PageIndexChanging(object sender, GridViewPageEventArgs e) 
    { 
     gridMain.PageIndex = e.NewPageIndex; 
     gridMain.DataBind(); 
    } 

    protected void gridMain_RowCommand(object sender, GridViewCommandEventArgs e) 
    { 
    //never gets here? 
    switch (e.CommandName.ToString()) 
     { 
      case "Buy": 
       PurchaseEnquiry(e.CommandArgument.ToString()); 
       break; 
     } 
    } 

    protected void PurchaseEnquiry(string enquiryId) 
    { 
     try 
     { 
      Enquiry enquiry = EnquiryMethods.Get(new Guid(enquiryId)); 
      Order order = OrderMethods.Purchase(supplier, enquiry); 
      Response.Redirect((new UrlFactory()).GetSupplierEnquiryMessageUrl(order.Id.ToString()), true); 
     } 
     catch (Exception e) 
     { 
      errorMessage = e.Message;   
     } 
    } 

} 

(SupplierInbox.aspx는 기본적으로 EnquiryList 및 html 만 포함합니다.

using System; 

public partial class SupplierInbox : System.Web.UI.Page 
{ 

    protected void Page_Load(object sender, EventArgs e) 
    { 
     (new Auth()).RequireClientOfType(ClientMethods.CLIENT_TYPE_SUPPLIER); 
     ucEnquiryList.Bind(EnquiryMethods.BuildQuery(new EnquiryQuery())); 
    } 

} 

GridView에서 Button을 계속 누르면

잘못된 포스트 백 또는 콜백 인수가 있습니다. 구성에서 이벤트 유효성 검사를 사용하거나 페이지에서 < % @ Page EnableEventValidation = "true"%>를 사용하여 이벤트 유효성 검사를 사용하도록 설정합니다. 보안상의 이유로이 기능은 포스트 백 또는 콜백 이벤트에 대한 인수가 원래 렌더링 된 서버 컨트롤에서 으로 시작됨을 확인합니다. 데이터가 유효하고 예상되는 경우 유효성 확인을위한 포스트 백 또는 콜백 데이터를 등록하려면 ClientScriptManager.RegisterForEventValidation 메서드를 사용하십시오.

EventValidation을 사용하지 않으면 버튼을 누르면 아무 것도 나타나지 않습니다. 즉, gridMain_RowCommand가 호출되지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

1

if (! IsPostBack) ucEnquiryList.Bind (EnquiryMethods.BuildQuery (new EnquiryQuery()));

+0

감사합니다. 나는 같은 문제가 있었는데 그것도 나를 위해 그것을 해결했습니다 –

+0

뿐만 아니라 수정 프로그램에서 활성화 EventValidation두고나요? – RSolberg