For passing Values between ASP.NET Web Forms how to create the instance of Source.aspx page(Source WebForm) in Target.aspx(Target WebForm ) page

Destination Web Form(Target.aspx.cs)

Not-Working code is shown below:

private void Page_Load (object sender, System.EventArgs e)
{
	//create instance of source web form
	WebForm1 wf1;//Problem here
	//get reference to current handler instance
	wf1=(WebForm1)Context.Handler;
	Label1.Text=wf1.Name;
	Label2.Text=wf1.EMail;
}

You can not pass value between pages like that. There are various techniques to pass value between pages:
- Using Session
Eg:On WebForm1

Session.Add("Name",txtName.Text);
       Session.Add("Email",txtEmail.Text);

On WebForm2

lblName.Text=Session["Name"].ToString();
        lblEmail.Text=Session["Email"].ToString();

- Using Static Properties or Variables

public partial class WebForm2 : System.Web.UI.Page
    {
        private static string _Name = string.Empty;

        public static string Name
        {
            get { return WebForm1._Name; }
            set { WebForm1._Name = value; }
        }
        private static string _Email = string.Empty;

        public static string Email
        {
            get { return WebForm1._Email; }
            set { WebForm1._Email = value; }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            lblName.Text = Name;
            lblEmail.Text = Email;
        }
    }

Now On WebForm1

WebForm2.Name=txtName.Text;
     WebForm2.Email=txtName.Text

- Using Constructor

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.