-2

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...

5
  • Well... I could stored testText in a DB (and modify it in Page2), and recover it in Page1. But, any better idea? Commented Jan 24, 2016 at 12:12
  • The question is about ASP.NET but the answer is plain WinForms. What's stranger is that the answer is accepted. Commented Dec 25, 2023 at 13:55
  • @MustafaÖzçetin You are confused. Please, review the question and your knowledge. Keep in mind that I formulate the problem and the answer solves it. Also, please check the reputation of the person responding. Many Thanks Commented Dec 25, 2023 at 17:43
  • I am not confused. To pass values between ASP.NET Web Forms/Pages you typically use session state or public property values from pages. Yo do not create new instances of pages and open them as in the answer but navigate/redirect between them. Architectures of ASP.NET and WinForms are very different. So can you please explain how the answer of an ASP.NET Web Page question be given using Windows Forms forms? Commented Dec 26, 2023 at 6:14
  • With regard to the reputation issue, it is roughly how much the community trusts you or how much you contribute to SO. I remember seeing a user who gains 260K reputation (yes 260K) by asking a single C++ question. So reputation is not an exact measure for knowledge or experience. If you don't want to acknowledge this fact then please compare my yearly reputation with the responder's one. But again, I don't attach importance to this. The responder certainly have a significant contribution to the community, by the way. Commented Dec 26, 2023 at 6:18

1 Answer 1

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

    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.