簡體   English   中英

如何在沒有客戶端事件的情況下從ASP.NET代碼后面調用jQuery UI對話框?

[英]How do I call up a jQuery UI dialog from ASP.NET code behind without a client-side event?

我試圖從C#ASP.NET代碼基於某個范圍之外的值而不是基於按鈕單擊或其他客戶端事件的情況下打開jQuery UI對話框。 這是應該創建對話框的Javascript函數(在.aspx頁的頂部):

<script type="text/javascript">
  //Total out of range dialog
  function ShowRangeDialog() {
    $('#rangeDialog').dialog({
      modal: true,
      width: 'auto',
      resizable: false,
      draggable: false,
      close: function (event, ui) {
        $('body').find('#rangeDialog').remove();
      },
      buttons:
      {
        'OK': function () {
          $(this).dialog('close');
        }
      }
    });
  }
</script>

這是對話框div本身(在.aspx頁的底部):

<div id="rangeDialog" style="display: none;" title="Total out of range">
  <p>
    Your line items total is out of the range allowed by the approval level you chose.
    Please check the approval range and adjust the line items or quantities.
  </p>
</div>

以下是C#代碼后面試圖顯示對話框的部分:

if (currTotal < lowerLim || currTotal > upperLim)
{
  //Show jQuery dialog telling user that their line items total is out of range
  Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "dlgOutOfRange",
    "ShowRangeDialog();", true);
}

如果我在調試器中單步執行,則會到達並執行if塊中的代碼,但不會顯示該對話框。 我想念什么?

我根據如何在后面的C#代碼中打開jQuery UI對話框中找到的問題/答案,對函數進行了少許修改 ,現在可以使用了。 這是修改后的函數:

<script type="text/javascript">
  //Total out of range dialog
  function ShowRangeDialog() {
    $(function() {
      $('#rangeDialog').dialog({
        modal: true,
        width: 'auto',
        resizable: false,
        draggable: false,
        close: function (event, ui) { $('body').find('#rangeDialog').remove(); },
        buttons: { 'OK': function () { $(this).dialog('close'); }
        }
      })
    }).dialog("open");
  }
</script>

嘗試這個

if (currTotal < lowerLim || currTotal > upperLim)
{
  //Show jQuery dialog telling user that their line items total is out of range
  Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "dlgOutOfRange",
    "ShowRangeDialog();", true);
}

您應該只調用函數名稱。

另外,您可能想嘗試使用啟動腳本而不是registerclientscriptblock。 您必須確保在定義函數之后而不是之前添加腳本。

if (currTotal < lowerLim || currTotal > upperLim)
{
  //Show jQuery dialog telling user that their line items total is out of range
  Page.ClientScript.RegisterStartupScript(this.GetType(), "dlgOutOfRange",
    "ShowRangeDialog();", true);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM