2016-01-24 100 views
-1

那么,这是形势... 我有一个Page1.aspx的元素(<h2 id="test"></h2>),我想它Page2.aspx(用户管理区......)发生变化,那种...从另一页面访问控制。 ASP.Net

test.InnerText = "testText"; 

如何从第二页触及此控件?那可能吗?

像往常一样,谢谢你们......

+0

嗯...我可以存储testText在DB(并修改它在第二页),并在第一页恢复。但是,有什么更好的主意? –

回答

1

你需要得到一个窗体的实例。见我的两个项目的形式下面 表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(); 
     } 
    } 
} 

表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"; 
     } 

    } 
} 
+1

感谢您的快速回答... jdweng :)。 我正在谈论Web表单... –

+1

仍然使用Webforms,您需要使用表单的一个实例。原理是一样的。 – jdweng

+0

嗯...有趣...我会检查出来,让你知道是否有可能...保持联系...干杯... –