从到达另一页控制。 ASP.Net [英] Reach control from another page. ASP.Net

查看:168
本文介绍了从到达另一页控制。 ASP.Net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那么,这是形势...
我有一个元素(/ H2 n =测试/)在Page1.aspx的,我想它Page2.aspx(用于用户管理区...),种...

Well, this is the situation... I have a element (/h2 id="test"/) 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...

推荐答案

您需要获取表单的一个实例。请参阅下面我的两个表格项目
表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();
        }
    }
}

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

    }
}

这篇关于从到达另一页控制。 ASP.Net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆