Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass information between web forms in asp.net

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.

like image 302
user3150674 Avatar asked Jan 01 '14 06:01

user3150674


2 Answers

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

like image 115
Arindam Nayak Avatar answered Nov 06 '22 22:11

Arindam Nayak


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

like image 39
user3108411 Avatar answered Nov 06 '22 23:11

user3108411