在从外部项目页面重定向此页面时,在页面加载时调用按钮单击事件不起作用,我按照以下步骤操作。
创建了一个项目并添加了一个页面,并在该页面中添加了一个链接按钮和 它的点击事件:
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弹出窗口未打开,并且未设置文本框控件的Text
属性。我的代码有什么问题?