我想在用户提交页面时显示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