사용자가 페이지를 제출할 때 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);
}
}
이것은 작동하지 않는다. .. 내가 무엇을 잘못하고 있냐? 고맙습니다! 대신 리터럴을 사용
게시 된 자바 스크립트와 서버 측 코드를 게시하십시오. – Oded