从外部项目页面重定向此页面时在页面加载时调用按钮单击事件不起作用,我遵循了这些步骤。
创建了一个项目并添加了一个页面,并在该页面中添加了一个链接按钮及其单击事件:
string url = "http://localhost:5934/Login.aspx"; string UserName = "XYZ"; string UserID = "123"; ASCIIEncoding encoding = new ASCIIEncoding(); string data = string.Format("UserNameFromPMS={0}&UserIDFromPMS={1}", UserName, UserID); byte[] bytes = encoding.GetBytes(data); HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(url); httpRequest.Method = "POST"; httpRequest.ContentType = "application/x-www-form-urlencoded"; httpRequest.ContentLength = bytes.Length; using (Stream stream = httpRequest.GetRequestStream()) { stream.Write(bytes, 0, bytes.Length); stream.Close(); } Response.Redirect("http://localhost:5934/Login.aspx");
在页面加载时直接调用该按钮的点击事件:
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { NameValueCollection nvc = Request.Form; //string userName; if (!string.IsNullOrEmpty(nvc["UserNameFromPMS"]) && !string.IsNullOrEmpty(nvc["UserIDFromPMS"])) { if (!string.IsNullOrEmpty(nvc["UserNameFromPMS"])) { userName = nvc["UserNameFromPMS"]; txtUsername.Text = nvc["UserNameFromPMS"].ToString(); } if (!string.IsNullOrEmpty(nvc["UserIDFromPMS"])) { txtPassword.Text = nvc["UserIDFromPMS"]; } } btnLogin_OnClick(sender, e); } }
并尝试在点击事件上打开模式弹出窗口:
protected void btnLogin_OnClick(object sender, EventArgs e) { mpeMessage.Show(); return; }
但是 Modal pop 没有打开,也Text
没有设置文本框控件的属性。我的代码有什么问题?