JavaScript Question

  • Thread starter Thread starter Greg Smith
  • Start date Start date
G

Greg Smith

I would like to call a JavaScript function to execute an alert() in my C#
program. I know you can add a call to an object event, but can you just
call it form code in your C# program?

Any help is greatly appreciated.
 
Use this class:

////////////////////////////////////////////////////////////////
Calling Example: MessageBox.Show(this, "Hello");
///////////////////////////////////////////////////////////////

public class MessageBox
{
private MessageBox(){}

public static void Show(System.Web.UI.Page Sender,string Msg)
{
Sender.Controls.Add(new System.Web.UI.LiteralControl("<script>alert(" +
Msg + "); </script>"));
}

}
 
public class MessageBox{
private MessageBox(){}

public static void Show(string Message){
System.Web.Ui.Page p = (Page)System.Web.HttpContext.Current.Handler;
string encodedMsg = System.Web.HttpUtility.HtmlEncode(Message);
p.RegisterClientScriptBlock("MessageBox",
"<script language=\"JavaScript\"> alert(\"" +
encodedMsg + "\");</script>");
}
}
 
Back
Top