I tried to post the selected ID number from source page into a new target page(pop up window) and display more details on that page.
I have googled the varies solutions but seem like they are a bit out of date.
Here are my questions:
What’s the best way to post it (session? cookie?) or Page.PreviousPage.FindControl? or add a control into <ItemTemplate>? or Javascript?
I don’t want to use a query string since I don’t want the user to manually modify it.
What should I write on the target page to grab that value?
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string testID= GridView1.SelectedRow.Cells[3].Text;
// eg. Session["ID"] = testID;
//eg. open new pop up window ("target.aspx");
}
Many thx
Although you could use store your selected value on a session variable or even cross-page postbacks, my preferred method and overall standard method is to use a simple querystring value.
1) Grab the value and redirect with the desired ID.
2) On the “target.aspx” page, load the values from the url (“http://localhost/target.aspx?Id=125“)
Passing variables between pages using QueryString.
Edit: Although I wouldn’t do such a thing (I like to keep my websites as stateless as possible), the same principle applies to session variables.
That being said, I don’t understand what’s the problem with querystrings. Sure, the user can modify it and insert bogus values, but that’s where your server-side validations come into place. And hey, if google uses querystrings, they can’t be all that bad.