Friday, April 23, 2010

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

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


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()
 for c sharp version mail me
info@amitech.co
www.amitech.co

No comments:

Amitech

Hell0 Friends,
i know you are stuck with some serious problems and that's why you are here. So friends i m putting all the solved problems(with solution) that i have faced in my life (technical problems) on this blog.
In case you can not find the proper solutions, feel free to mail me at info@amitech.co
Amit Panchal