我想在用戶提交頁面時顯示Javascript。我通過後面的代碼調用這個Javascript(我認爲這很簡單)。這裏是我的代碼:從CodeBehind頁面顯示Javascript不工作!
MessageBox1("Testing my Message"); //Calling Function!
private void MessageBox1(string msg) //This is in the code behind of the page.
{
// Cleans the message to allow single quotation marks
string cleanMessage = msg.Replace("'", "\\'");
string script = "<script type=\"text/javascript\">alert('" + cleanMessage + "');</script>";
// Gets the executing web page
Page page = HttpContext.Current.CurrentHandler as Page;
// Checks if the handler is a Page and that the script isn't allready on the Page
if (page != null && !page.ClientScript.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(typeof(CommSetup), "alert", script);
}
}
這不工作......我在做什麼錯在這裏?謝謝!
發佈呈現的JavaScript以及服務器端代碼。 – Oded 2011-04-29 14:48:46