Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

so here is the code for test.aspx page

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();


}

so here is the code for test1.aspx page

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
274 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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

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?

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...