You must Sign In to post a response.
  • Category: ASP.NET

    Transfer data from one page to another

    i have 2 webpages. Page1 contains admission details. i want to get data from page1 to page2 when i click a button for modification
  • #767309
    Hi,
    Following are some of the ways to transfer data from one page to another:
    1. Session:
    WebForm1.aspx

    Session["Details"]= TextBox1.Text;
    Response.Redirect("WebForm2.aspx");

    WebForm2.aspx

    if(Session["Details"]!= null)
    Label1.Text = Session["Details"].ToString();


    2. Cookies:
    WebForm1.aspx

    HttpCookie objCookie = new HttpCookie("Details");
    objCookie.Value = TextBox1.Text;
    Response.Cookies.Add(objCookie);
    Response.Redirect("WebForm2.aspx");

    WebForm2.aspx

    if (Request.Cookies["Details"] != null )
    Label1.Text = Request.Cookies["Details"].Value;


    3. Query String:
    WebForm1.aspx

    Response.Redirect("WebForm2.aspx?Details="+ TextBox1.Text);

    WebForm2.aspx
    if (Request.QueryString["Details"]!= null)
    Label1.Text = Request.QueryString["Details"];

    4. You may use GET-SET properties.

  • #767327
    Hi,


    Refer below..
    You can use sessions for this, to pass data from one page to other page.
    If you use sessions you can use session data with in the application.

    In Sessions we can store datasets, arrays, objects info also.
    It can carry unlimited data, any kind of data (text, image etc) and there is no limitations per browser to carry the session information for an application.

    If sample from Page1 is datatable, add it to session like below..
    Session.Add("samplefromPage1 ", Ssample);


    To retrieve session data table,

    DataTable Page2Table= (DataTable)Session["Ssample"];


    Hope this will help you.

    Regards,
    SonyShiva
    Never lose hope..You never know what tomorrow will bring

  • #767328
    Hi

    you can maintain following methods

    1.session
    2.Querystring

    session["EmpID"]

    Response.Redirect("Page2.aspx?empid=100");

    Name : Dotnet Developer-2015
    Email Id : kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #767335
    Hi,

    You can send data from one page to another page in different ways

    1) Sessions
    2) QueryString
    3) Cookies
    4) HiddenFields( if the page is incorporated with in same browser)

    based on content you want to transfer you can choose any one of those, if data is minimal then you may choose QueryStrings, Cookies, HiddenFields, if the data is huge then you can use Sessions to transfer it from one page to another page.

    Ex:

    Page1 :

    Session["Data"]=//your data;

    Response.Redirect("Page2.aspx",true);


    In page2 just get the data from session and store that in one varriable.


    Page2

    string data=Sttring.Empty;
    if(session["Data"]!=null)
    data=Session["Data"] as string;


    Hope this will helpful to you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments