Pass Value From One Web Page To Another in Asp.Net
Suppose there is a scenario in which you want when you click on some text then associated value should pass to another page and with the help of this associated value you can do anything. That link my be simply in paragraph or in Grid View or in Data list.
There may be many methods to do it and I hope one of them called 'Session' be in you knowledge. But doing this with help of session is not considered good so here we will use other technique as well..
Suppose you have Page 'a.aspx' and other page 'b.aspx' you want to pass value from one to another then on first page write this code but before this suppose you have a link button on click of this associated value will pass to 'b.aspx'.
code on click event of link button in 'a.aspx'
Response.Redirect("b.aspx?value=" + here you should write variable of reference variable);
Response.Redirect("b.aspx");
on the page 'b.aspx' of page load event write following code (you can take this value in variable in the form of string.
string passedvalue= Request.QueryString["value"];
here value will carry the assigned value from one page to another. But if you are using Grid View and have link and want to display associated data on other page. Then you will have to use OnRowCommand="shashi_RowCommand" event of Grid View and corresponding command name property of link button so that various link button associated with Grid View can perform various tasks.
In my example.
here i have two link buttons in my grid view that's why used two command name so that they can perform various task associated with them. You will have to give command name in link button. see this image.
There may be many methods to do it and I hope one of them called 'Session' be in you knowledge. But doing this with help of session is not considered good so here we will use other technique as well..
Suppose you have Page 'a.aspx' and other page 'b.aspx' you want to pass value from one to another then on first page write this code but before this suppose you have a link button on click of this associated value will pass to 'b.aspx'.
code on click event of link button in 'a.aspx'
Response.Redirect("b.aspx?value=" + here you should write variable of reference variable);
Response.Redirect("b.aspx");
on the page 'b.aspx' of page load event write following code (you can take this value in variable in the form of string.
string passedvalue= Request.QueryString["value"];
here value will carry the assigned value from one page to another. But if you are using Grid View and have link and want to display associated data on other page. Then you will have to use OnRowCommand="shashi_RowCommand" event of Grid View and corresponding command name property of link button so that various link button associated with Grid View can perform various tasks.
In my example.
here i have two link buttons in my grid view that's why used two command name so that they can perform various task associated with them. You will have to give command name in link button. see this image.
Comments
Post a Comment