0

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

Edited by mudunuru: Changing code

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by sharadcp
0

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

Edited by __avd: Added [code] tags.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.