Well, this is the situation…
I have a element (<h2 id="test"></h2>
) in Page1.aspx, and I want to change it from Page2.aspx (administration zone for the user…), kind of…
test.InnerText = "testText";
How can I reach this control from the second page? Is that possible?
As usual, thanks you guys…
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You need to get an instance of the form. See my two form project below
Form 1
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form1 : Form { Form2 form2; public Form1() { InitializeComponent(); form2 = new Form2(this); } private void button1_Click(object sender, EventArgs e) { form2.Show(); string results = form2.GetData(); } } }
Form 2
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace WindowsFormsApplication1 { public partial class Form2 : Form { Form1 form1; public Form2(Form1 nform1) { InitializeComponent(); this.FormClosing += new FormClosingEventHandler(Form2_FormClosing); form1 = nform1; form1.Hide(); } private void Form2_FormClosing(object sender, FormClosingEventArgs e) { //stops form from closing e.Cancel = true; this.Hide(); } public string GetData() { return "The quick brown fox jumped over the lazy dog."; } } }
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0