public static void MyAlert(System.Web.UI.Page AspxPage, string StrMessage, string StrKey) { string StrScript; StrScript = "<script language=javaScript>alert('" + StrMessage + "')</script>"; if (AspxPage.IsStartupScriptRegistered(StrKey) == false) { AspxPage.RegisterStartupScript(StrKey, StrScript); } }
/// <summary> /// ���ܣ��ڿͻ���ע��һ��ű�����,��Page����� form Ԫ�صĽ������֮ǰ�����ýű� /// ���룺page ��ҳ�е�Page���� /// script ��ע���JavaScript�ű�����Ҫ���� script language=javascript �ȱ�ǩ /// ������ޡ� /// </summary> /// <param name="page">��ҳ�е�Page����(this)</param> /// <param name="script">��ע���JavaScript�ű�����Ҫ���� script language=javascript �ȱ�ǩ</param> public static void RegisterStartupScript(System.Web.UI.Page page, string script) { string strKey; int i; //ע��ű����Key strKey = System.DateTime.Now.ToString(); //ѭ����ֱ���ҵ�ij��û��ע�����Key for (i = 0; i < 100; i++) if (!page.IsStartupScriptRegistered(strKey + i.ToString())) break; page.RegisterStartupScript(strKey + i.ToString(), script); }
/*=====================================================================================================*/ public static bool CreateMessageAlertForAspxPage(System.Web.UI.Page aspxPage, string strMessage) { string strScript = "<script language=JavaScript>alert( \"" + strMessage + "\" )</script>"; if (!aspxPage.IsStartupScriptRegistered("strKey1")) { aspxPage.RegisterStartupScript("strKey1", strScript); } return false; }
/*=====================================================================================================*/ public static bool CreateMessageAlertToAWebPage(System.Web.UI.Page aspxPage, string strMessage, string pagename) { string strScript = @"<script language=JavaScript>alert('" + strMessage + "'); window.location.href('" + pagename + "')</script>"; if (!aspxPage.IsStartupScriptRegistered("strKey1")) { aspxPage.RegisterStartupScript("strKey1", strScript); } return false; }
/*=====================================================================================================*/ public static bool CreateMessage(System.Web.UI.Page aspxPage, string strMessage) { string strScript = @"<script language=JavaScript>alert('" + strMessage + "'); self.close();</script>"; if (!aspxPage.IsStartupScriptRegistered("strKey1")) { aspxPage.RegisterStartupScript("strKey1", strScript); } return false; }