2013-02-21 93 views
1

我通過代碼隱藏調用javascript。給對象預期的錯誤。我如何通過ShowDialog()函數傳遞一些值?在代碼隱藏中調用javascript

這裏是我在代碼隱藏

ClientScript.RegisterStartupScript(GetType(), "Call my function", "ShowDialog("Value_here");", true); 

,並在我的javascript代碼

<script type="text/javascript"> 
    var IRProjectID = 0; 

    function ShowDialog(UnitID) { 
     radconfirm("Are you sure you want to approve this Help Desk item?", confirmBackChecked); 
     IRProjectID = UnitID; 
    } 

    function confirmBackChecked(arg) { 
     if (arg == true) { 
      __doPostBack(IRProjectID, 'Approve'); 
     } 
    } 
    </script> 

回答

1
ClientScript.RegisterStartupScript(this.GetType(), "Call My Function", "ShowDialog("Value_here");", true); 
0

試試這個

ClientScript.RegisterStartupScript(this.GetType(), "Test", "ShowDialog("+Value_here+");", true); 
+1

嗨iBlue同樣的錯誤.. – kirk 2013-02-21 09:20:46

+0

u能告訴我其中rü得到錯誤exactly.Is它運行時錯誤或編譯錯誤。 – iJade 2013-02-21 09:26:07

+0

這是一個runtie錯誤 – kirk 2013-02-21 09:28:42

0

也許你還爲時過早調用javascript函數...與嘗試Page.RegisterClientScriptBlock

當您調用JavaScript函數時請小心。確保它存在!!!之前。

編輯

Page.RegisterClientScriptBlock已經過時了,用ClientScriptManager.RegisterClientScriptBlock

+0

'Page.RegisterClientScriptBlock'已過時。 – Rawling 2013-02-21 09:33:04

+1

ClientScriptManager.RegisterClientScriptBlock – 2013-02-21 09:34:10

+0

¿你的頁面上有ScriptManager嗎? – 2013-02-21 09:37:12

0

我認爲錯誤是由你身邊Value_here使用雙引號拋出

ClientScript.RegisterStartupScript(GetType(), "Call my function", "ShowDialog("Value_here");", true); 

試試這個

ClientScript.RegisterStartupScript(GetType(), "Call my function", "ShowDialog(\"Value_here\");", true); 

ClientScript.RegisterStartupScript(GetType(), "Call my function", "ShowDialog('Value_here');", true);