2012-02-24 47 views
3

我想從我的代碼隱藏中調用一個javascript函數。 在我的按鈕單擊事件處理程序,我有:from page * .aspx.cs call javascript function

protected void load_data_Click(object sender, EventArgs e) 
{ 
    if (dt.Rows.Count == 1) 
     { 
      BindDl();      
     } 
     else 
     { 
      //if dt.rows.count! = 1 I want to call a JavaScript function where be one alert! how to do? 
     } 
} 

回答

2

This page will be helpful for you

// Get a ClientScriptManager reference from the Page class. 
ClientScriptManager cs = Page.ClientScript; 
Type cstype = this.GetType(); 
String csName = "MyAlertFunction"; 

// Check to see if the startup script is already registered. 
if (!cs.IsStartupScriptRegistered(cstype, csName)) 
{ 
    String jsFunction = "yourFunctionHere()"; 
    cs.RegisterStartupScript(cstype, csName, jsFunction, true); 
} 
1

用戶紙條經理

ScriptManager.RegisterStartupScript(this, typeof(string), "SHOW_ALERT", "alert('')", true); 

其中地方警報,你可以把你的JavaScript代碼,腳本下一個參數真放自動標記所以你不要必須寫他們。

相關問題