Reader Level:

Posting Form Data from ASP.NET Page to Another URL

By Jigar Desai on Sep 27, 2004
This article shows you how to post a Form data to a different URL from ASP.NET pages. For example, you might need to send user to a third party payment processing system using post method. ASP.NET does not provide any straight forward way to accomplish this task.


Sometime you need to post a form to an different url from pages, for example you might need to send user to third party payment processing system using post method, does not provide any straight forward way to accomplish this task.

Problem which most users faces with server side form in aspx page are, you are not allowed to change action of form and you are allowed to use only one server side form per page.

Possible Solutions

  1. One possible solution to this problem is to Create your own form control and use it on page this will allow you to change action of form, but again what if you do not want some existing input elements in current page to go to post.
  2. There is good way to post form data using HttpWebResponse & HttpWebRequest class if you want to post data behind the scenes, but if you want to post data using user browser then you are stuck.

Our Solution

I will try to show you one possible way to accomplish this task, we will create

  1. component that will create form with required fields and post the form to specified url, 
  2. web page that will use that component to post data and 
  3. page which will receive that data and display posted data.

A) RemotePost Class.

public class RemotePost
private System.Collections.Specialized.NameValueCollection Inputs = new System.Collections.Specialized.NameValueCollection();
public string Url = "";
public string Method = "post";
public string FormName = "form1";
public void Add(string name,string value)
public void Post()
for(int i=0;i< Inputs.Keys.Count;i++)

Properties of our component 

  1. "Url" which is action of our form. 
  2. "Method" which is Method of our form, default is Post but you can also use Get 
  3. "FormName" which is name of form.

Methods of our component. 

  1. "Add" which will be used to add form input name and value. and 
  2. "Post" which will render html on page to do actual posting, most important part of this method is onload event of rendered html's body which will post form to specified URL.

and private field Inputs which will hold name value pair collection of all inputs that goes into form.

you can compile this class to dll and use in your project but for simplicity I am including that class directly into page itself.

B) Sample Page.

Following is sample page code which posts form to specified url.

RemotePost myremotepost = new RemotePost();
myremotepost.Url =;
myremotepost.Post() ;

C) Receiving Page.

Following is sample page code which posts form to specified url.

This is the page where posting will occur for simplicity we will just write posed value so that we can know what was posted.

<%@ Page Language="C#" %>
<script runat="server">
void Page_Load(object sender, EventArgs e){
if (Request.Form["field1" != null ){
Response.Write("field1 : " + Request.Form["field1" + "")}
if(Request.Form["field2" != null ){
Response.Write("field2 : " +Request.Form["field2" + "")}

Run Sample

Click "" target="new">here to run sample

There will be cases where you will need to tweak the code to suit your requirement. you will also need to check scenario where user uses back button of browser(from posted page) which will cause form to be posted again.

Article Extensions
Contents added by kuldeep singh on Jul 10, 2013
    i  needed exactly what you have shown in your
but problem is that when i run this code locally it works fine and when i use it for iis hosted web application in it does not work

can u suggest some solution?

 protected void Page_Load(object sender, EventArgs e)
        System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo("en-GB");
        //   txtUserId.Text = System.Net.Dns.GetHostName();   
      if (Request.Form["email" ]!= null )
           txtUserId.Text = Request.Form["email"];
           Session["postedemail"] = Request.Form["email"];
          Response.Write("email :emty");
Contents added by anil babu on Aug 01, 2012
What is URL REDIRECTION?How can i use this concept in my .net?
my task is i have generated one url like this ""
I am passing one pearameter like ""
I want to display Ename in Database table that corresponding "Empno"
plz Help me Give me one simple example

I am new this concepts
plz Help me send source code to my
Jigar Desai
Jigar Desai

Jigar Desai is a Microsoft certified professional and has 8 years of experience in Microsoft technologies, he is working in since pre beta releases and has extensive experience in developing database driven web ... Read more

Personal Blog: