在单击按钮时获取由jquery分配的label值

本文关键字:分配 label jquery 单击 按钮 获取 | 更新日期: 2023-09-27 18:04:06

我使用Bootstrap v3.3 Modal,我用jquery给标签赋值,我怎么能得到c#中button_click分配的标签值?我可以将值传递给文本框,我可以从文本框中获取值,但不能从标签中获取值。我使用下面的代码:

<div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
   <div class="modal-dialog" role="document">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
               <h4 class="modal-title" id="exampleModalLabel" runat="server"></h4>
         </div>
         <div class="modal-body">
            <div class="form-group">
               <label for="recipient-name" id="lblOldValue" class="control-label" runat="server">Brand:</label>
               <asp:TextBox ID="txtUpdate" runat="server" class="form-control"></asp:TextBox>
            </div>
         </div>
         <div class="modal-footer">
            <asp:Button ID="btnUpdate" runat="server" class="btn btn-primary" Text="Save" OnClick="btnUpdate_Click"/>
         </div>
      </div>
   </div>
</div>

$('#exampleModal').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget); // Button that triggered the modal
        var recipient = button.data('whatever'); // Extract info from data-* attributes
        var modal = $(this);
        modal.find('.modal-title').text('Edit: ' + recipient);
        modal.find('modal-body lable').val(recipient);
        modal.find('.modal-body input').val(recipient);
    });
protected void btnUpdate_Click(object sender, EventArgs e)
{
    string newValue = txtUpdate.Text;
    string oldValue = lblOldValue.InnerText;
}

在单击按钮时获取由jquery分配的label值

我找到了一个使用隐藏字段的解决方案。

<asp:HiddenField ID = "hfName" runat = "server" />
document.getElementById("<%=hfName.ClientID %>").value = recipient;
string oldValue = Request.Form[hfName.UniqueID];