23 April 2010

How to send values from one aspx page to another aspx page using post method

Written by Amit Panchal, Posted in Blog

Problem:
How to send values from one aspx page to another aspx page using "post method"
Solution:
Create a class named RemotePost.vb
and add the following code in that class

Imports Microsoft.VisualBasic
 
Public Class RemotePost
 
    Private Inputs As System.Collections.Specialized.NameValueCollection = New System.Collections.Specialized.NameValueCollection
 
    Public Url As String = ""
    Public Method As String = "post"
    Public FormName As String = "form1"
    Public Sub Add(ByVal name As String, ByVal value As String)
        Inputs.Add(name, value)
    End Sub
    Public Sub Post()
        System.Web.HttpContext.Current.Response.Clear()
        System.Web.HttpContext.Current.Response.Write("")
        System.Web.HttpContext.Current.Response.Write(String.Format("", FormName))
        System.Web.HttpContext.Current.Response.Write(String.Format("
 
 
", FormName, Method, Url)) Dim i As Integer = 0 Do While i < Inputs.Keys.Count System.Web.HttpContext.Current.Response.Write(String.Format("", Inputs.Keys(i), Inputs(Inputs.Keys(i)))) i += 1 Loop System.Web.HttpContext.Current.Response.Write("
") System.Web.HttpContext.Current.Response.Write("") System.Web.HttpContext.Current.Response.End() End Sub End Class
", FormName, Method, Url))
Dim i As Integer = 0
Do While i < Inputs.Keys.Count
System.Web.HttpContext.Current.Response.Write(String.Format("", Inputs.Keys(i), Inputs(Inputs.Keys(i))))
i += 1
Loop
System.Web.HttpContext.Current.Response.Write("

")
System.Web.HttpContext.Current.Response.Write("")
System.Web.HttpContext.Current.Response.End()
End Sub
End Class
now from any page from which u want to pass the value
use the following code

Dim myremotepost As RemotePost = New RemotePost
myremotepost.Url = "targetURL.aspx"
myremotepost.Add("param_name", "param_value")
myremotepost.Post()

if you have any doubts feel free to comment us

Social Bookmarks

About the Author

Amit Panchal

Co-Founder,

Amitech Business Solutions

All Events

Textify

Comments (0)

Leave a comment

You are commenting as guest. Optional login below.

Cancel Submitting comment...