Post问题求助,如何将A页面post到B的值在B页片面的控件中显示。

jxyaolp 2006-09-01 09:23:43
Post问题求助,如何将A页面post到B的值在B页片面的控件中显示。

我网上抄了段代码:
A页 post
string postData = "uUsername=abc&uPassword=ccc";
byte[] data = System.Text.Encoding.GetEncoding("GB2312").GetBytes(postData);
string postUrl = "http://localhost:5880/WebSitePostTest/B.aspx";

// 准备请求...
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(postUrl);
try
{
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = data.Length;
Stream stream = req.GetRequestStream();

// 发送数据
stream.Write(data, 0, data.Length);
stream.Close();

HttpWebResponse rep = (HttpWebResponse)req.GetResponse();
Stream receiveStream = rep.GetResponseStream();
Encoding encode = System.Text.Encoding.GetEncoding("GB2312");
StreamReader readStream = new StreamReader(receiveStream, encode);

Char[] read = new Char[256];
int count = readStream.Read(read, 0, 256);
StringBuilder sb = new StringBuilder("");
while (count > 0)
{
String readstr = new String(read, 0, count);
sb.Append(readstr);
count = readStream.Read(read, 0, 256);
}
rep.Close();
readStream.Close();
Response.Write(sb.ToString());

Response.Write("Login success!");
return true;
}
catch (Exception ex)
{
Response.Write("Login error:" + ex.Message.ToString());
return false;
}
Response.Redirect("http://localhost:5880/WebSitePostTest/B.aspx");


B页 Page_Load(object sender, EventArgs e)接收
string aa = Request.ServerVariables["REQUEST_METHOD"];

if (aa.Trim().ToUpper() == "POST")
{



if (Request.Form["uPassword"] != null && Request.Form["uUsername"] != "")
{

string uUsername = Request.Form["uUsername"].ToString();
string uPassword = Request.Form["uPassword"].ToString();
this.TextBox1.Text = uUsername+uPassword;



}

}



问题: this.TextBox1.Text 显示时为空。
调过调试发现,B页Page_Load方法会运行两次。
不解。
...全文
188 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
leafsword_519 2006-10-25
  • 打赏
  • 举报
回复
倒分?
yaoliping 2006-10-25
  • 打赏
  • 举报
回复
hTML控件名称有部分自动产生,介意在事件中生成一段HTML代码
cyy1981 2006-10-09
  • 打赏
  • 举报
回复
Response.Redirect("http://localhost:5880/WebSitePostTest/B.aspx")
在这个地方运行第二次
jxyaolp 2006-09-01
  • 打赏
  • 举报
回复
不行的,调试时发现Page_Load方法会运行两次,而且isPostBack都为false
leafsword_519 2006-09-01
  • 打赏
  • 举报
回复
那你把
if (aa.Trim().ToUpper() == "POST")
{



if (Request.Form["uPassword"] != null && Request.Form["uUsername"] != "")
{

string uUsername = Request.Form["uUsername"].ToString();
string uPassword = Request.Form["uPassword"].ToString();
this.TextBox1.Text = uUsername+uPassword;



}

这段写到isPostBack里试试

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧