功能存在于pageB.aspx中,参数从pageA传递过来。我无法获得 pageB 的结果。这里应该做什么。
pageA.aspx.cs:
string URI = Server.MapPath("~/pageB.aspx");
NameValueCollection UrlParams = new NameValueCollection();
UrlParams.Add("section", "10");
UrlParams.Add("position", "20");
using (WebClient client = new WebClient())
{
byte[] responsebytes = client.UploadValues(URI, "POST", UrlParams);
string responsebody = Encoding.UTF8.GetString(responsebytes);
}
当编译器读取 byte[] 时,会出现一个对话框,询问是否应对 pageB 进行更改。单击“否”时,没有任何反应。字符串“responsebody”为空。
pageB.aspx.cs::
protected void Page_Load(object sender, EventArgs e)
{
if (int.TryParse(Request.QueryString["section"], out section)
&& int.TryParse(Request.QueryString["position"], out position))
{
ProcessData();
}
}
private string ProcessData()
{
string HTMLContent = string.Empty;
try
{
//some code to render the string.
return HTMLContent;
}
catch (Exception ex)
{
throw ex;
}
}
我想从 pageB 获取 'HTMLContent'
最佳答案
使用 HttpContext.Current.Request["Key"] 代替 Request.QueryString["Key"]。
if (int.TryParse(HttpContext.Current.Request["section"], out section)
&& int.TryParse(HttpContext.Current.Request["position"], out position))
{
ProcessData();
}
关于c# - 如何从另一个页面获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29889693/