关于发布数据编程到另一个aspx页面的问题 [英] issue regarding post data programmatically to another aspx page

查看:93
本文介绍了关于发布数据编程到另一个aspx页面的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我有像Test.aspx文件和test1.aspx页面。 Test.aspx文件中有一个按钮,当点击按钮,然后例行被称为将编程数据公布至test1.aspx页和test1.aspx页面将显示数据。

basically i have to pages like test.aspx and test1.aspx. test.aspx has one button and when button click then a routine is being called which will post data programmatically to test1.aspx page and test1.aspx page will show the data.

protected void Button1_Click(object sender, EventArgs e)
{
    PostForm();
}

private void PostForm()
{

    WebRequest request = WebRequest.Create("http://localhost:14803/PaypalCSharp/Test1.aspx");
    request.Method = "POST";
    request.ContentType = "application/x-www-form-urlencoded";
    string postContent = string.Format("parameter1={0}&parameter2={1}", "Hello", "Wow");
    byte[] postContentBytes = Encoding.ASCII.GetBytes(postContent);
    request.ContentLength = postContentBytes.Length;
    Stream writer = request.GetRequestStream();
    writer.Write(postContentBytes, 0, postContentBytes.Length);
    writer.Close();


}

所以这里是code为test1.aspx页

protected void Page_Load(object sender, EventArgs e)
{
    if (IsPostBack)
    {
        string str1 = Request.Form["parameter1"];
        string str2 = Request.Form["parameter2"];
    }
}

我只是不明白什么是错在我的code,结果数据不会发布到该页面。基本上,我想,当用户在Test.aspx文件点击按钮,然后数据将公布Test.aspx的网页编程test1.aspx页面,test1.aspx将与发布的数据浏览器显示。请指导我什么,我需要在我的code改变,结果我的要求将被履行。谢谢

i just do not understand what is wrong in my code as a result data is not posting to that page. basically i want that when user click on button in test.aspx then data will post from test.aspx page to test1.aspx page programmatically and test1.aspx will show in the browser with posted data. please guide me what i need to change in my code as a result my requirement will be fulfill. thanks

推荐答案

我觉得你所做的事情更难比他们需要。这里有一些其他的选项:

I think you've made things harder than they need to be. Here are some other options:

你为什么不Response.Redirect的在Button1_Click的方法test1.aspx,并在查询字符串传递两个参数?

Why don't you Response.Redirect to test1.aspx in the Button1_Click method and pass the two parameters in the query string?

或者,如果你不想在GET请求所做的工作,你为什么不搬进test1.aspx的code到Button1_Click方法,然后重定向后完成?到test1.aspx

Or, if you don't want the work done in a GET request, why don't you move the code in test1.aspx into the Button1_Click method and then redirect to test1.aspx after completion?

另外,为什么不去做一个跨页后回test1.aspx(尽管跨页投递是依赖于JavaScript)?

Alternatively, why not do a cross page post back to test1.aspx (although cross page posting is dependent on javascript)?

这篇关于关于发布数据编程到另一个aspx页面的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆