8

how to send some information from one web form to another web form in asp.net first web form is HumanList.aspx that shows the list of humans in a GridView component. when user click edit link, i want to pass humanID (value of human record ID) from HumanList.aspx to another web form named HumanEdit.aspx. In humanEdit.aspx, i want to load that human (With humanID) and fill human information into text boxes.

1
  • Typically, queryString is use for this, not Session.
    – roydukkey
    Commented Jan 1, 2014 at 6:11

5 Answers 5

14

There are many ways to pass params between pages.

  1. Use Querystring.

Source page - Response.Redirect("second.aspx?param=value");

Destination page - Request.QueryString["param"].

  1. Use Session.

Source page - Session["param"] = "value"; value is set here.

Destination page - Session["param"].ToString(). value is retrieved here.

  1. Use PreviousPage property. Note: This applies if you redirect from first.aspx ( just an example here), to second.aspx , then you can use PreviousPage.<propname> in second.aspx to values set in first.aspx.

In second.aspx you need to add directive like this <%@ PreviousPageType VirtualPath="~/first.aspx" %>.

  1. Use Request.Form to read posted values.

If there are input, dropdownlist existing in source page and you are posting value to second.aspx, then you can read posted value using Request.Form["input_id"].

  1. Use cookies to transfer values. First save some value to cookie from first.aspx and read that value from second.aspx.

Refer to MSDN for more info - MSDN link

1

Consider using session or query string.

Session could be used like

pass value

 Session["value"]=someValue;

get value like

 var value= Session["value"].toString();

You could pass values with the help of properties too

-1

I would suggest storing it in the session state: http://msdn.microsoft.com/en-us/library/ms178581.aspx

-1

Well, there are many ways to pass information page to page.

one primary way is by QueryString

//To Send
private void submit_Click(object sender, System.EventArgs e)
{
    string ID = String.Empty;

    ID = "192" // Have your ID Here

    Response.Redirect("humanEdit.aspx?ID=" + ID );
}


//To Receive
private void Page_Load(object sender, System.EventArgs e)
{
   String ID = String.Empty;
   ID=Request.QueryString["name"];
}

Another Method is Sessions

//Store your ID from Sending Page
Session["ID"]= "143"; //Example ID

//To Recieve
private void Page_Load(object sender, System.EventArgs e)
{
   String ID = String.Empty;
   ID=Session["ID"].toString();
}

And there are many other ways too...

2
  • Negative Voters can explain why this answer got down vote?
    – Kirk
    Commented Dec 12, 2015 at 5:47
  • ID=Request.QueryString["name"]; or ID=Request.QueryString["ID"]; ?
    – Kiran RS
    Commented Apr 19, 2016 at 7:27
-2

Say You have a gridview1 with a button field Say "Modify" First Provide a command Name to that field Say "Mod" Now in Gridview1_RowCommand() function of HumanList.aspx page write the code like this-

switch (e.CommandName.Trim())
{
case "Mod":
int r1=Int32.Parse((e.CommandArgument).ToString());
Session["id"]=GridView1.DataKeys[r1].Value.ToString();
Response.Redirect("HumanEdit.aspx?id=" + Session["id"]);
break;
}

Now in HumanEdit.aspx.cs you can make your own class and with in that class you can have a datatable object.Store the Sql query in that object and call that class in page_load(). Say class is

Public void show()
{
Within datatable object you can write your query like this
select x,y,z, from tbl_name where id=" + Request.QueryString["id"]
if(dt.Rows.Count>0)
{
Xtext.Text=dt.Rows[0]["x"].ToString();
Ytext.Text=dt.Rows[0]["y"].ToString();
Ztext.Text=dt.Rows[0]["z"].ToString();
}
}

This much of code is enough to get what you want.

1
  • @user3150674: Hello, If you feel like you have got help from the post, please mark it as answer. Thank You. Feel free to ask your queries.
    – Omi
    Commented Jan 4, 2014 at 8:16

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.