Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8031641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:10:28+00:00 2026-06-05T01:10:28+00:00

I am bit confused in using httpwebrequest. I tried to look into some articles

  • 0

I am bit confused in using httpwebrequest. I tried to look into some articles but not able to get much from it as I am doing it for the first time. Below is the code I am trying to work on and I have few questions,

a) The ASPX page has few controls defined and in code-behind I create few controls. When I do httpwebrequest with POST, do I need to consider all controls and their values? I need to do POST for one of the controls only. Can I do it only for that control?

b) What URL should be specified in “(HttpWebRequest)WebRequest.Create”? I assume it is the same page that is shown to the user. For example in my example below it is (“http://localhost/MyIdentity/Confirm.aspx?ID=New&Designer=True&Colors=Yes”);

c) Is there anything else I need to modify or take care of either in markup or code to achieve httpwebrequest?

    private void OnPostInfoClick(object sender, System.EventArgs e)
{
    ASCIIEncoding encoding = new ASCIIEncoding();
    string postData =  ""; //Read from the stored array and print each element from the array loop here. 
    byte[] data = encoding.GetBytes(postData);

    // Prepare web request...
    HttpWebRequest myRequest =
      (HttpWebRequest)WebRequest.Create("http://localhost/MyIdentity/Confirm.aspx?ID=New&Designer=True&Colors=Yes");
    myRequest.Method = "POST";
    myRequest.ContentType = "application/x-www-form-urlencoded";
    myRequest.ContentLength = data.Length;
    Stream newStream = myRequest.GetRequestStream();
    // Send the data.
    newStream.Write(data, 0, data.Length);
    newStream.Close();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T01:10:30+00:00Added an answer on June 5, 2026 at 1:10 am

    You typically would only use it for server-to-server communication (not necessarily for page to page data transfer).

    If I’m understanding your post and question correctly, you just seem to want to send POST data to some other page in your ASP.Net application. If so, one way you can do that is to simply change the PostBackUrl of your submit button (form target) instead of the normal Postback (to same page).

    There are other ways, but this should be the simplest.

    <asp:Button ID="Button1" runat="server" Text="Button" PostBackUrl="foo.aspx" />
    

    In the above, instead of POSTing back to itself, the POST will be sent to foo.aspx where you can examine/use/process the POSTed data.


    Update based on your comment:

    You don’t have to code your way through HttpWebRequest for that. The normal ASP.net WebForms model does it for you.

    Given this simple ASP.net web Forms page:

    <form id="form1" runat="server">
    
    Coffee preference:
    <asp:RadioButtonList ID="CoffeeSelections" runat="server" RepeatLayout="Flow" RepeatDirection="Horizontal">
       <asp:ListItem>Latte</asp:ListItem>
       <asp:ListItem>Americano</asp:ListItem>
       <asp:ListItem>Capuccino</asp:ListItem>
       <asp:ListItem>Espresso</asp:ListItem>
    </asp:RadioButtonList>
    
    <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
    
    ....
    </form>
    

    Your inline or code behind would look something like this:

    protected void Page_Load(object sender, EventArgs e)
    {
       //do whatever you want to do on Page_Load
    }
    
    
    protected void Button1_Click(object sender, EventArgs e)
    {
       //handle the button event
       string _foo = CoffeeSelections.SelectedValue;
       ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bit confused here, I have an on-demand instance but do I get charged even
A bit confused, I was watching some video where some guy was using sqllite
I'm a bit confused about using STL set::find() for a set of my own
I'm a bit confused over the .net redistributables... Our C# code uses some API
I'm a bit confused about inheritance under sqlalchemy, to the point where I'm not
I'm a bit confused whether or not I should make the links on my
I'm a bit confused about mvc terminology. Using the question title as an example,
I am a bit confused. I know that by using Formset we could generate
I am learning UI programming using QT and i am bit confused by what
I'm using SQLite as my database, and I'm a little bit confused about how

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.