1090807更新
//要引用JavaScriptSerializer類別 , NET 3.5 以上版本才有
using System.Web.Script.Serialization;
try
{
}
catch(Exception ex)
{
var message = new JavaScriptSerializer().Serialize(ex.Message.ToString());
var script = string.Format("alert({0});", message);
ScriptManager.RegisterClientScriptBlock(page, page.GetType(), "", script, true);
}
2.HttpContext.Current.Response.Write("<script>alert('第二種方式,有白色底!')</script>");
1070412測試可用下面這行
HttpContext.Current.Response.Write("<script>alert('!!! 訊息錯誤 !!! : " + err.Message + "');</script>");
3.public static void Show(System.Web.UI.Page page, string msg)
{
page.ClientScript.RegisterStartupScript(page.GetType(), "message", "<script language='javascript' defer>alert('" + msg.ToString() + "');</script>");
}
Show(this, "第三種方式,不會有白色底!");
4.Response.Write("<script>alert('第四種方式,有白色底!')</script>");
5.window.showModalDialog('XXX.aspx', '', 'dialogWidth:429px;dialogHeight:200px;location:no,menubar:no,toolbar:no,status:no');
6.Page.clientscript.registerstartupscript(this.gettype(), "", "<script>window.open('../issue/issueallcomment.aspx');</script>");
7.如果使用ajax控制項的話
System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "opennewwindow", "alert('彈出來的內容!');", true);
8.在頁面body的最後一行個控制項,在給這個給控制項值,如:
label.Text="<script>alert('彈出來的內容!'); </script> ";
9.可以傳參數,注意 ' 跟 " 的排列
string strtmp = "if (confirm('此病歷號碼尚未收案,是否要新增收案')) {window.location.href = 'Default2.aspx?patno=" + txtselect.Text +"';}";
ClientScript.RegisterStartupScript(GetType(), "ScriptKey",strtmp, true);
10. ClientScript.RegisterClientScriptBlock(this.GetType(), "ScriptBlock", "alert('RegisterClientScriptBlock OK!!')", true);
11 ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('" + values + "');</script>", true);
注意 " 雙引號跟 ' 單引號 ,錯誤會造成無法使用
ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('帳號驗證結果 : 錯誤 " + strcheck + "');</script>");
1070412測試可用下面這行
ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert(" + "'" + Lbl_msg.Text + "'" +");</script>");// ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('存檔錯誤:'" + Lbl_msg.Text + "');</script>");
//下面是使用web服務的 alert
string strid = TextBox1.Text.Trim();
string strpw = TextBox2.Text.Trim();
ServiceReference1.ServiceSoapClient ws = new ServiceSoapClient();
if (ws.CheckHISAccount(strid, strpw) == 0)
{
ws.Close();
//基本的 alert
// ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('帳號驗證結果 : 正確 ');</script>");
//轉址的 alert,斷行 \\n
//ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('帳號驗證結果 : 正確\\n按 確定 轉往 Pacs');location.href='http://192.168.xxx.xxx';</script>");
//確認再轉址的alert
ClientScript.RegisterStartupScript(GetType(), "message", "<script>if (confirm('帳號驗證結果 : 正確\\n\\n按 確定 轉往 Pacs 視窗')) {window.location.href ='http://192.168.xxx.xxx';}</script>");
//確認再轉址的alert ScriptManager
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "alert", "alert('修改成功!'); location.href='Default.aspx';", True)
//另開新視窗
// ClientScript.RegisterStartupScript(GetType(), "message", "<script>window.open('http://192.168.xxx.xxx','新視窗的名稱');</script>");
//純.net轉址
// Response.Redirect("http://192.168.xxx.xxx");//登入ok後,轉址去pacs視窗
}
else {
string strcheck = ws.CheckHISAccount(strid, strpw).ToString();
ws.Close();
//下面script注意 " 跟 ' 符號的包圍的前後順序
ClientScript.RegisterStartupScript(GetType(), "message", "<script>alert('帳號驗證結果 : 錯誤 " + strcheck + "');</script>");
}
沒有留言:
張貼留言