Created
January 25, 2016 15:25
-
-
Save aromig/255ab89b9f3b65d92b89 to your computer and use it in GitHub Desktop.
Dynamically create JavaScript alert & confirmation dialogs from server side C#
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void CreateAlert(string key, string alertString) | |
{ | |
Page page = HttpContext.Current.Handler as Page; | |
if (page != null) | |
{ | |
if (!page.ClientScript.IsStartupScriptRegistered(key)) | |
{ | |
page.ClientScript.RegisterStartupScript(typeof(Page), key, "<script language=\"JavaScript\">alert(\"" + alertString + "\");</script>"); | |
} | |
} | |
} | |
public static void CreateConfirm(System.Web.UI.WebControls.Button btn, string confirmString) | |
{ | |
btn.Attributes.Add("onclick", "return confirm(\"" + confirmString + "\");"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment