Home >Backend Development >C++ >How Can I Access and Modify Controls on One ASP.NET Page from Another?
In the asp.net across page access control
Assume that you have an element in Page1.aspx, such as
& gt; label, you want to modify it from another page (Page2.aspx). Can you access and operate this control remotely?
<h2
<决> Solution
In ASP.NET, you can access the control by obtaining a form instance. For this, please consider the following technologies:
<骤> Step 1: Create a new project
Create a new ASP.NET Web window application in Visual Studio. <骤> Step 2: Design page1.aspx
In Page1.aspx, add a
& gt; label:
<骤> Step 3: Design Page2.aspx <h2
<code class="language-html"><h2></h2></code> </p> <p> <strong> Explanation: </strong> </p> <p> </p> Examples of the previous page (PAGE1.ASPX). <pre class="brush:php;toolbar:false"><code class="language-csharp">using System.Web.UI.HtmlControls; public partial class Page2 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { // 获取Page1.aspx的实例 Page1 page1 = (Page1)Page.GetPreviousPage(); // 将其转换为HTMLControl HtmlGenericControl h2 = (HtmlGenericControl)page1.FindControl("test"); // 修改InnerText属性 h2.InnerText = "已修改的文本"; } }</code>
convert to allow you to access the attribute of & gt; label.
Page.GetPreviousPage()
HtmlGenericControl
<h2
InnerText
InnerText
To access the control control from multiple levels, you may need to change the previous page multiple times. <h2
The above is the detailed content of How Can I Access and Modify Controls on One ASP.NET Page from Another?. For more information, please follow other related articles on the PHP Chinese website!