2016-01-24 123 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

嗯...有趣...我會檢查出來,讓你知道是否有可能...保持聯繫...乾杯... –