Home Search Member List Faq Register Login  
JavaScript Tips
Pass data from one page to another using post

Thread Starter: Karamasoft   Started: 09-18-2007 12:48 PM   Replies: 0
 Karamasoft Support Forums » General Discussions » JavaScript Tips » Pass data from one page to another using post
 Printable Version    « Previous Thread   Next Thread »
  18 Sep 2007, 12:48 PM
Karamasoft is not online. Last active: 11/10/2017 3:24:14 PM Karamasoft

Top 10 Posts
Joined on 09-05-2004
Posts 6,818
Pass data from one page to another using post

If you need to pass small amounts of data from one page to another, you can pass it in the query string and the target page can retrieve it through Request.QueryString collection (GET operation). However, if you need to pass large amount of data you cannot pass it in the query string since Internet Explorer has maximum 2048 character limit on the address of the page. In these cases, you can pass data from one page to another using POST operation.

In your source page, define a hidden variable to hold the data to pass and pass only its ID to the target page in the query string.

The target page should first get that ID through Request.QueryString collection. Then it should set its own hidden variable value with the one in the source frame on the clientside during BODY onload event handler. You can use opener object on the client-side to retrieve the DOM elements in the opener page. Then it should do a postback to itself and retrieve the value of its hidden variable through Request.Form collection.

Source Page JavaScript

function PassData(ctlID) {

window.open('TargetPage.aspx?ctlID=' + ctlID, 'NewWindow',




Source Page ASPX

<asp:TextBox ID="txtPassData" runat="server" Text="Data to pass"


<asp:Button ID="btnPassData" runat="server" Text="Pass Data"

CssClass="Button" OnClientClick="PassData('txtPassData'); return false;"


Target Page JavaScript

function Body_Onload() {

var pageStatusElem = document.getElementById('hfPageStatus');

// Page status hidden field value is initially empty string

if (pageStatusElem.value == '') {

// Set text to spell check hidden field value to the text in the

opener window

document.getElementById('hfTextPassed').value =



// Set page status hidden field value so that when the page is

posted back it can process text to spell check retrieved from the opener


pageStatusElem.value = '<%=SET_TEXT%>';

// Post back the page




Target Page ASPX

<body onload="Body_Onload()">

<form id="form1" runat="server">


Text passed: <asp:Label ID="lblTextPassed" runat="server"



<asp:HiddenField ID="hfTextPassed" runat="server" Value="" />

<asp:HiddenField ID="hfPageStatus" runat="server" Value="" />



Target Page C#

public const string SET_TEXT = "SetText";

public const string TEXT_IS_SET = "TextIsSet";

protected void Page_Load(object sender, EventArgs e)


// Initial entry

if (hfPageStatus.Value == SET_TEXT)


// Set page status not to enter again

hfPageStatus.Value = TEXT_IS_SET;


lblTextPassed.Text = hfTextPassed.Value;


 Page 1 of 1 (1 items)
Karamasoft Support Forums » General Discussions » JavaScript Tips » Pass data from one page to another using post

You can add attachments
You can post new topics
You can reply to topics
You can delete your posts
You can edit your posts
You can create polls
You can vote in polls
Forum statistics are enabled
Forum is unmoderated

© 2002-2018 Karamasoft LLC. All rights reserved.