Assume that i have 2 .aspx page (From.aspx and To.aspx)
and i have a hyperlink control inside the From.aspx which navigate to To.aspx and i used javascript to open a new window..

so now i have a Label inside From.aspx which have text = 1000. and i want pass it to To.aspx label value and to display. how can i do that? i've tried so many ideas with my reasearch, but i still can't work with it.

Dani AI

Generated

Brief recap: the goal is to open To.aspx from From.aspx (client-side JS) and show the Label value (1000) on the new page. pointed out passing values page→page; ended up using cookies. Below are practical alternatives, small examples, and the main tradeoffs so the pattern is clear years later.

A simple, reliable client-side option is to build the URL and open it with the value URL-encoded. This keeps everything stateless and works even if the new window is navigated independently.

// From.aspx (client-side)
var srcId = '<%= Label1.ClientID %>';
var amount = document.getElementById(srcId).innerText || '';
var url = 'To.aspx?amt=' + encodeURIComponent(amount);
window.open(url, '_blank', 'width=800,height=600');

If you prefer no visible query string and both pages are same-origin, use direct cross-window communication: have the child expose a function and the opener call it once the child is ready.

// To.aspx: expose a receiver
function receiveAmount(v){
  document.getElementById('<%= lblTarget.ClientID %>').innerText = v;
}

// From.aspx: open and wait until the function exists, then call it
var w = window.open('To.aspx','_blank');
var t = setInterval(function(){
  if (w && typeof w.receiveAmount === 'function') {
    w.receiveAmount(document.getElementById('<%= Label1.ClientID %>').innerText);
    clearInterval(t);
  }
}, 100);

For structured or cross-origin cases, use postMessage (and always check e.origin). Other choices: session state or server-side storage (keeps data off the URL), cookies (as used — persistent but visible to client), or Server.Transfer/PreviousPage for server-side transfers. Key cautions: always URL-encode/HTML-encode and validate any client-derived data to avoid XSS or tampering; query strings are visible and size-limited; cross-window DOM access only works same-origin. Choose the method that matches security, lifetime, and visibility requirements.

Recommended Answers

All 4 Replies

You can pass it as a query string in the URL. The. On the receiving page use the server.querystring collection to retrieve the value.

could you show me a simple example?
i've tried using PostBackUrl attribute and PreviousPage.FindControl() but is still can't work. :/

I am not clear on what you are doing on the from page, but you need to build the hyperlink so that it contains the query string parameter and value. For example,

yourDomain.com/to.aspx?q=1000

Then on the to.aspx page you can retrieve that value in the page load subroutine.

Vb example.

Label1.text = request.querystring("q")

You can also pass values from page to page if the source page is using a form. On the receiving page you can use request.form() to retrieve the values.

i've solved the problem by using cookie method and globa method :) Thanks anyway.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.