请教一个脚本问题
我自己写了一个类,用来向客户端页面加入脚本弹出提示信息框,但是一直不能实现,请大家帮忙看看。
public class MsgBoxShow{ public MsgBoxShow() { // //TODO: 在此处添加构造函数逻辑 // } /// <summary> /// 显示“确定”,点击后转到预设的网址 /// </summary> /// <param name="strMsg">提示信息</param> /// <param name="URL">转跳网址</param> public static void MsgBoxShowInfoAndRedirct(System.Web.UI.Page page, string strMsg, string URL) { StringBuilder builder = new StringBuilder(); builder.Append("<language='javascript' defer>"); builder.AppendFormat("alert('{0}');",strMsg); builder.AppendFormat("top.location.href='{0}';", URL); builder.Append("</script>"); page.RegisterStartupScript("message", builder.ToString()); }}
protected void btnSubmit_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(); conn.ConnectionString = ConfigurationManager.ConnectionStrings["connStr"].ConnectionString; SqlCommand cmd = new SqlCommand(); cmd.Connection = conn; cmd.CommandText = "select * from users where username='" + txtUserName.Text.Trim() + "'"; conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); if (dr.Read()) { if (dr[2].ToString() == txtPwd.Text.Trim()) { MsgBoxShow.MsgBoxShowInfoAndRedirct(this,"登陆成功!", "ManageNews.aspx"); //Session["UserName"] = txtUserName.Text.Trim(); //Response.Redirect("NewsManage.aspx"); } else { MsgBoxShow.MsgBoxShowInfoAndRedirct(this, "密码错误!请重新输入", "login.aspx"); } } else { MsgBoxShow.MsgBoxShowInfoAndRedirct(this, "查无此用户!请重新输入", "login.aspx"); } }