2013-07-22 2 views
0

큰 문제가 있습니다. 내 ..._ItemDataBound(...) 이벤트에서 내 DataList에있는 컨트롤을 찾을 수 있지만, AsyncPostBackTrigger 컨트롤을 찾을 수 없다면 큰 문제가 있습니다. 나 널. 코드 숨김asp.net findcontrol 메서드는 null을 반환합니다. AsyncPostBackTrigger

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
<ContentTemplate> 
    <asp:DataList ID="DataListGallery" runat="server" RepeatColumns="3" RepeatDirection="Horizontal" OnItemDataBound="DataListGallery_ItemDataBound" > 
     <ItemTemplate> 
      <asp:LoginView ID="LoginView1" runat="server"> 
       <LoggedInTemplate> 
        <asp:HiddenField ID="FieldPhoneId" Value='<%# Eval("Phone_InfoID") %>' runat="server" />      
         <img src="../images/cart.gif" alt="" title="" border="0" class="left_bt" /></a>--%> 
          <asp:ImageButton ID="btnShop" OnClick="btnShop_Click" ImageUrl="images/cart.gif" CssClass="left_bt_item" title="header=[خريد] body=[&nbsp;] fade=[on]" runat="server" />      
         <img src="../images/favs.gif" alt="" title="" border="0" class="left_bt" /></a>--%> 
          <asp:ImageButton CssClass="left_bt_item" title="header=[مورد علاقه] body=[&nbsp;] fade=[on]" OnClick="btnFavourite_Click" ID="btnFavourite" ImageUrl="images/unfav.png" runat="server" />      
         <img src="../images/favorites.gif" alt="" title="" border="0" class="left_bt" /></a>--%>      
       </LoggedInTemplate> 

<Triggers> 
        <asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Command"></asp:AsyncPostBackTrigger> 
        <asp:AsyncPostBackTrigger ControlID="LinkButton2" EventName="Command" /> 
        <asp:AsyncPostBackTrigger ControlID="LinkButton3" EventName="Command" /> 
        <asp:AsyncPostBackTrigger ControlID="LinkButton4" EventName="Command" /> 
        <asp:AsyncPostBackTrigger ControlID="LinkButton5" EventName="Command" /> 
        <asp:AsyncPostBackTrigger ControlID="LinkButton6" EventName="Command" /> 
        <asp:AsyncPostBackTrigger ControlID="LinkButton7" EventName="Command" /> 
        <asp:AsyncPostBackTrigger ControlID="LinkButton0" EventName="Command" /> 
        <asp:AsyncPostBackTrigger ControlID="btnSearchHead" EventName="Command" /> 
        <asp:AsyncPostBackTrigger ControlID="LinkButton8" EventName="Command" /> 
        <asp:AsyncPostBackTrigger ControlID="lnkNext" EventName="Click" /> 
        <asp:AsyncPostBackTrigger ControlID="lnkPrevious" EventName="Click" />     
       </Triggers> 

과 : 내가 로그인을하고있어 AsyncPostBackTrigger를 사용하는 경우

protected void DataListGallery_ItemDataBound(object sender, DataListItemEventArgs e) 
{ 
    if (User.Identity.IsAuthenticated) 
    { 
     // Get LoginView for access to ImageButton on it. 
     var loginView = e.Item.FindControl("LoginView1"); 

     ImageButton btnFav = (ImageButton)loginView.FindControl("btnFavourite"); 
     HiddenField hf = (HiddenField)loginView.FindControl("FieldPhoneId"); 

     List<int> listFav = (List<int>)Session["Fav"]; 

     if (listFav.Contains(int.Parse(hf.Value))) 
      btnFav.ImageUrl = "~/images/favs.gif"; 
    } 
} 

, 나는이 컨트롤에 액세스 할 수 없습니다 btnFavhf

여기 내 영문 코드입니다. 그들은 LoginView 안에 있음을 주목하십시오.

감사합니다.

답변

0

는이 사이트에서 내 문제를 해결 : enter link description here

protected void Page_Load(object sender, EventArgs e) 
{ 
    //http://www.aspdotnetfaq.com/Faq/how-to-determine-whether-an-asynchronous-partial-postback-has-occurred-on-page.aspx 

    // get a reference to ScriptManager and check if we have a partial postback 

    if (ScriptManager.GetCurrent(this.Page).IsInAsyncPostBack) 
    { 

     // partial (asynchronous) postback occured 

     // insert Ajax custom logic here 

    } 
    // enable property is re-creating page controls 
    else if (!Page.IsPostBack || enable) 
    { 
     //enable = false; 
     if (Page.Request["Page"] != null || Page.Request["Page"] != "") 
     {... 

는이 사이트에서 감사합니다.

관련 문제