2017-10-13 27 views
0

得到变量ASP在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--%> 

代码隐藏:

<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> 

我:

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){ } 
    } 

这里通过隐藏代码被触发脚本在方法之外声明变量id_imobiliaria_pagamento,并且在代码隐藏中正常恢复数据。

但是这个相同的变量,模态打开,并在模态内的HTML代码中调用,什么也没有显示。有谁能够帮助我?

回答

0

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