2014-11-16 65 views
0

以下更新是我的網頁編碼HiddenField值並不在行更新

<div class="alert alert-danger alert-error" style="display:none" id="alertErrorMessage"> 
     <a href="#" class="close" data-dismiss="alert">&times;</a> 
     <strong>Error! </strong><% =HiddenField1.Value %> 
    </div> 

    <asp:HiddenField ID="HiddenField1" runat="server" Value="init HF value"/> 

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
        <ContentTemplate> 
         <asp:GridView ID="gridViewAll" runat="server" CssClass="table table-striped table-hover table-bordered" 
          AutoGenerateColumns="False" DataKeyNames="ImageId" 
          OnRowEditing="gridViewStage_RowEditing" 
          OnRowCancelingEdit="gridViewStage_RowCancelingEdit" 
          OnRowUpdating="gridViewStage_RowUpdating"> 
..... 
</ContentTemplate> 
       </asp:UpdatePanel> 

然後我下面的編碼更新的隱藏字段的值並顯示警報。 但它仍然顯示警告框中的'init HF值'。但它應該顯示'新HF值'而不是那個。 這背後的原因是什麼?

protected void gridViewStage_RowUpdating(object sender, GridViewUpdateEventArgs e) 
     { 
StringBuilder sb = new StringBuilder(); 
      sb.Append(@"<script>"); 
      sb.Append("$('#HiddenField1').val('New HF Value');"); 
      sb.Append("$('#alertErrorMessage').css('display', 'block');"); 
      sb.Append(@"</script>"); 
      ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ErrorMessageAlert", sb.ToString(), false); 
} 

回答

0

我解決它加入我的警告框到一個UpdatePanel

<asp:UpdatePanel ID="UpdatePanel7" runat="server"> 
     <ContentTemplate> 
      <div class="alert alert-danger alert-error" style="display: none" id="alertErrorMessage"> 
       <a href="#" class="close" data-dismiss="alert">&times;</a> 
       <strong>Error! </strong><% =hiddenFieldErrorMessage.Value %> 
      </div> 
     </ContentTemplate> 
    </asp:UpdatePanel> 
0

這也許相關帖子可以幫助您或提供進一步的指導:

Asp .net hidden field can't set value with jquery 好運!

+0

@ user966398另外,請看到這個帖子: [鏈接](http://stackoverflow.com/questions/9639152/change-隱場價值與 - jQuery的和得到最新價值的服務器) –