Modal BootStrap无法从代码隐藏中获取变量asp

时间:2017-10-13 16:12:21

标签: javascript c# asp.net bootstrap-modal

在MinhasVendas2.aspx:

<div id="myModal" class="modal fade">
  <div class="modal-dialog">
    <div class="modal-content">
      <!-- dialog body -->
      <div class="modal-body">
        <button type="button" class="close" data-dismiss="modal">&times;</button>
        Forma de Pagamento

        <%--  <%# Eval("desc_tp_pagamento") %>
          teste--%>
      </div>
        <div class="modal-body">    
         Dados Pagto: <%=id_imobiliaria_pagamento%>
            <label id="lblteste"></label>    
      </div>
      <!-- dialog buttons -->
      <div class="modal-footer"><button type="button" id="a.btn" class="btn btn-primary"data-dismiss="modal">OK</button></div>
    </div>
  </div>
</div>
            <%--#modalformapagto fim--%>

代码隐藏:

public void gdvPagamentos_SelectIndexChanged(object sender, EventArgs e)
    {
        try
        {
            System.Threading.Thread.Sleep(1000);
            List<pagamento> pagto = new List<pagamento>();
            var id_imobiliaria_pagamento = gdvPagamentos.SelectedRow.Cells[0].Text;
            //ClientScript.RegisterClientScriptBlock(this.GetType(), "", "myModal();", true);
            ScriptManager.RegisterStartupScript
                 (Page,
                  this.GetType(),
                  "script",
                  "myModal();",
                  true);
        }
        catch(Exception ex){ }
    }

以下是通过codebehind触发的脚本:

<script type="text/javascript">
                function myModal() {    
                    $("#myModal").modal();    
                    $("#myModal").on("show", function () {    // wire up the OK button to dismiss the modal when shown
                        $("#myModal a.btn").on("click", function (e) {
                            console.log("button pressed");   // just as an example...
                            $("#myModal").modal('hide');     // dismiss the dialog
                        });
                    })
                };
                    function myModalHide() {
                        $("#myModal").on("hide", function () {    // remove the event listeners when the dialog is dismissed
                            $("#myModal a.btn").off("click");
                        })
                    };

                    function myModalHidden() {
                        $("#myModal").on("hidden", function () {  // remove the actual elements from the DOM when fully hidden
                            $("#myModal").remove();
                        });

                        $("#myModal").modal({                    // wire up the actual modal functionality and show the dialog
                            "backdrop": "static",
                            "keyboard": true,
                            "show": true                     // ensure the modal is shown immediately
                        })
                    }
                ;
</script>

我在方法之外声明变量id_imobiliaria_pagamento,并且在代码隐藏中恢复正常的数据。

但是这个相同的变量,模态打开,并在模态内部的html代码中调用,没有显示任何内容。有人能帮助我吗?

1 个答案:

答案 0 :(得分:0)

在代码隐藏中,在方法内部,我已经在一个表单中声明了变量(例如var xxxxx),并且在我定义为字符串的方法之外......这就发生了不显示它的问题...奇怪没有指责错误。我纠正了方法中的tb字符串,并显示了变量的内容。