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
I would suggest storing it in the session state: http://msdn.microsoft.com/en-us/library/ms178581.aspx
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
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.
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...
There are many ways to pass params between pages.
Querystring. Source page - Response.Redirect("second.aspx?param=value");
Destination page - Request.QueryString["param"].
Session.Source page - Session["param"] = "value"; value is set here.
Destination page - Session["param"].ToString(). value is retrieved here.
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" %>.
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"].
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