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.
-
Typically, queryString is use for this, not Session.– roydukkeyCommented Jan 1, 2014 at 6:11
5 Answers
There are many ways to pass params between pages.
- Use
Querystring
.
Source page - Response.Redirect("second.aspx?param=value");
Destination page - Request.QueryString["param"]
.
- Use
Session
.
Source page - Session["param"] = "value";
value is set here.
Destination page - Session["param"].ToString()
. value is retrieved here.
- Use
PreviousPage
property. Note: This applies if you redirect fromfirst.aspx
( just an example here), tosecond.aspx
, then you can usePreviousPage.<propname>
insecond.aspx
to values set infirst.aspx
.
In second.aspx
you need to add directive like this <%@ PreviousPageType VirtualPath="~/first.aspx" %>
.
- 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"]
.
- Use
cookies
to transfer values. First save some value to cookie fromfirst.aspx
and read that value fromsecond.aspx
.
Refer to MSDN for more info - MSDN link
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
I would suggest storing it in the session state: http://msdn.microsoft.com/en-us/library/ms178581.aspx
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...
-
-
ID=Request.QueryString["name"]; or ID=Request.QueryString["ID"]; ?– Kiran RSCommented Apr 19, 2016 at 7:27
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.
-
@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.– OmiCommented Jan 4, 2014 at 8:16