2011-10-02 28 views
0

我有使Ajax調用的JQuery代碼,爲了重用相同的代碼,我將代碼放在了.JS文件中。JQueryUI對話框不能在JS文件中工作

這是場景。

1)我的aspx頁面中有超鏈接控件和div控件。 div控件用於顯示JQueryUI對話框消息。

2)我有一個接收超鏈接對象和DIV對象

3)在JS文件我是通過JQuery的阿賈克斯插入記錄的參考,這是工作好JS文件,但問題是,它沒有顯示JQuery用戶界面對話

代碼爲

在aspx文件

<asp:HyperLink ID="hlInsertRecord" runat="server" Text="Insert Record" Font-Bold="true" /> 

<div id="pnlInsertRecordMsg" title="Insert Record"></div> 

在Aspx.cs文件(綁定JavaScript函數的引用)

string strInsertRecord = "InsertRecord(" + hlInsertRecord.ClientID + ",pnlInsertRecordMsg);return false;"; 
      hlInsertRecord.Attributes.Add("onclick", strInsertRecord); 

請注意:的AutoOpen:如此,我檢查我的代碼在取消打開對話框 在.js文件

function InsertRecord(hlInsertRecord, pnlInsertRecordMsg) { 
    $(document).ready(function() { 

     //--------Message Box Start------------------- 
     // increase the default animation speed to exaggerate the effect 
     $.fx.speeds._default = 900; 
     $(function() { 
      $(pnlInsertRecordMsg.id).dialog({ 
       autoOpen: true, 
       resizable: false, 
       show: "highlight", 
       hide: "fade" 
      }); 

      //   $(hlInsertRecord.id).click(function() { 
      //    $(pnlInsertRecordMsg.id).dialog("open"); 
      //    return false; 
      //   }); 
     }); 
     //--------Message Box End------------------- 



     pnlInsertRecordMsg.innerHTML = "Please wait, we are sending your request..."; 
     $.ajax({ 
      type: "POST", 
      url: hlInsertRecord.href, 
      success: OnInsertRecordSuccess, 
      error: OnInsertRecordFail 
     }); 
     //}); 

     function OnInsertRecordSuccess(response) { 
      hlInsertRecord.innerHTML = "Record Inserted"; 
      pnlInsertRecordMsg.innerHTML = response; 
      setTimeout(function() { $(pnlInsertRecordMsg.id).dialog("close"); }, 2000); 
     } 

     function OnInsertRecordFail(response) { 
      pnlInsertRecordMsg.innerHTML = "Oops we are unable to send your request. Please try again!!!"; 
      setTimeout(function() { $(pnlInsertRecordMsg.id).dialog("close"); }, 10000); 
     } 

    }); 
} 
+1

$(pnlInsertRecordMsg.id).dialog ..你在這裏得到正確的對話框ID嗎? – Priyank

+0

是的,我得到正確的ID –

回答

1

我不明白爲什麼你使用這個$(pnlInsertRecordMsg.id)
我想這裏應該$('#pnlInsertRecordMsg')。dialog
如果我錯了,那麼糾正我。