c# - 如何从另一个页面获取数据

标签 c# asp.net webforms

功能存在于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/

相关文章:

c# - WCF 调用者未通过 WsDualHttpBinding 中的服务进行身份验证

c# - 提供程序命名管道提供程序错误 40 无法打开到 SQL Server 错误 2 的连接

c# - 使用 ASP.Net 从 HTML 发送电子邮件

c# - 如何解决 System.StackOverflowException : 'Exception of type ' System. StackOverflowException' 被抛出。生成随机代码时出现异常?

ASP.NET webforms 列表框 - 跨页发布

c# - 如何从我的 Hololens 中编辑 Streamingassets 中的 XML 文件

c# - HTTP 407(需要代理身份验证)

asp.net - 如何在 IIS 上为 ASP.NET 设置正确的文件权限

c# - 从数据库表中查找数据

c# - 在 View 状态中存储控件的自定义属性