Home >Backend Development >C++ >How Can I Access Controls on One ASP.NET Page from Another?
Accessing controls on one ASP.NET page from another isn't directly possible due to the page lifecycle and variable scope. However, several methods enable indirect interaction.
The Session object provides a persistent key-value store across page requests. On the source page (e.g., Page1.aspx), store the relevant data in the session:
<code class="language-javascript">window.sessionStorage.setItem('testText', 'New Page Value');</code>
On the target page (e.g., Page2.aspx), retrieve the data and update the control:
<code class="language-javascript">var testElement = document.getElementById('test'); var testText = window.sessionStorage.getItem('testText'); if (testText) { testElement.innerText = testText; }</code>
While hidden fields or query strings offer alternative data transfer mechanisms, they are less robust and elegant than using the Session object. The Session object offers a more centralized and manageable approach for cross-page communication.
The above is the detailed content of How Can I Access Controls on One ASP.NET Page from Another?. For more information, please follow other related articles on the PHP Chinese website!