2014-01-08 37 views
0

我曾經有過很奇怪的問題我加了Ajax updatepanel當發生按鍵事件 以防止整個頁面加載。我添加了 按鈕事件,但當我運行調試器chek代碼 進程文本框儘管我添加了文本返回空。當我嘗試將文本框移出更新面板時,發現 按鈕事件找不到文本框控件。所以有什麼問題?TextBox不能在Ajax UpdatePanel中工作

<asp:DataList ID="DL_userpost" runat="server" CssClass="single-posts" RepeatColumns="1" 
     OnItemCommand="DL_userpost_ItemCommand"> 
     <ItemTemplate> 
      <div class="single-posts"> 
       <div class="post-user"> 
        <a href="#"></a> 
       </div> 
       <div class="post-container-all"> 
        <div class="post-user-single-img"> 
         <asp:Image ID="Img_Twasol" runat="server" ImageUrl='<%# Eval("Post_File")%>' Width="130" 
          Height="99" /></div> 
        <div class="post-user-single-data-tabs"> 
         <div class="post-user-single-data-title"> 
          <%#Eval("User_Name")%> 
         </div> 
         <div class="post-user-single-data-text"> 
          <%#Eval("Post_Content")%> 
         </div> 
        </div> 
       </div> 
       <div class="comment"> 
         <asp:UpdatePanel ID="UPPublicComment" runat="server" > 
           <ContentTemplate> 
            <asp:Panel ID="pnpublicpost" runat="server" DefaultButton="Btn_publicpost"> 
             <asp:TextBox runat="server" ID="txt_publicpost" CssClass="comment-tabs2"></asp:TextBox> 
             <asp:ImageButton ID="Btn_publicpost" CommandName="publicpost" ValidationGroup="publicpost" 
              runat="server" OnClick="Btn_publicpost_Click" Style="display: none" /> 
             <asp:Label ID="LblpublicpostPID" runat="server" Text='<%#Eval("Post_ID")%>' Visible="false"></asp:Label> 
            </asp:Panel> 
           </ContentTemplate> 
          </asp:UpdatePanel> 
         </div> 
        </div> 
       </div> 

      </div> 
      </div> 
     </ItemTemplate> 
    </asp:DataList> 
+1

什麼後面的代碼是您使用訪問文本框? – Andrei

+0

我剛剛複製並將您的代碼粘貼到新的WebApplication窗體中,解僱了它,在框中鍵入我的名字,然後按Enter鍵。方法命中斷點和我的名字在txt_publicpost.Text中返回 –

回答

0

UpdatePanel添加UpdateMode="Conditional"

<asp:UpdatePanel runat="server" ID="UpdInfo" UpdateMode="Conditional"> 
    <ContentTemplate> 
     <asp:TextBox ID="TxtInfo" runat="server /> 
    </ContentTemplate> 
</asp:UpdatePanel> 
+0

默認情況下'updatemode'是'always',所以它在每次回傳時刷新內容 – Grundy

+0

是的,它不應該是有條件的,除非你想更新它從後面的代碼 –

+0

@MikeyMouse'條件'只有你想要調用'updatePanel.Update()' – Grundy

1

我確切地複製到你的標記代碼從上面的代碼使這個方法的背後...你的代碼看起來不錯

enter image description here

+0

我不認爲海報想要更新價值。或者,我誤解了這一點。如果他這樣做,那麼是的,他需要將UpdateMode設置爲條件並調用更新。 –

+0

我添加完整的aspx頁面,我注意到Datalist的問題,但我不明白爲什麼? – skdeveloper

+0

@skdeveloper是的,一旦你使用DataList,你需要使用OnCommand方法。如果你想看看他們在框中輸入的內容,它會變得更加複雜,你需要使用jQuery或其他東西來獲取該值並設置命令參數。當他們點擊評論框中的輸入時,你想要做什麼? –

相關問題