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
<h2></h2>
<明> Explanation:
<索> Examples of the previous page (PAGE1.ASPX).
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 = "已修改的文本"; } }
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!