ClientScript.RegisterStartupScript用來向前台頁面注冊script腳本。
//此處是從頁面接受變量,然後彈出
string mm =Request["name"];
string yhm=Request["pswd"];
ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javas
小注:
C#傳入變量時記住要"+變量名+"這麼成對的傳入。alert()的括號中需要有一對單引號,引起其中的變量。
//下面這句,可以實現彈出對話框後,單擊確定同時關閉頁面
ClientScript.RegisterStartupScript(this.GetType(), "message", "<script language='javas
string a = "aaaa";
string b = "bbbb";
string c = "cccc";
ClientScript.RegisterStartupScript(this.GetType(), "IsPostBack1", " <script> alert('IASID=" + a + ",Result=" + b + ",UserAccount=" + c + "' ); </script> ");
初始狀態:
ClientScript.RegisterStartupScript(this.GetType(), "IsPostBack1", " <script> alert(''); </script> ");
第一步寫上,需要原樣輸出的內容:
ClientScript.RegisterStartupScript(this.GetType(), "IsPostBack1", " <script> alert('IASID=',Result=,UserAccount='); </script> ");
第二步寫上,變量:
ClientScript.RegisterStartupScript(this.GetType(), "IsPostBack1", " <script> alert('IASID=" + a + ",Result=," + b + "UserAccount=" + c + "'); </script> ");
ok完成!
相同顏色的逗號彼此配對。