0

I've two text boxes in one page and after those text boxes two separate search buttons, search buttons redirect to another page where user searchs and result is displayed in a grid, there can be multiple results, each row of grid contains 'select' command so that when user clicks on select of perticular row its data is selected and page redirects to previous page and data of row is displayed in textbox..

I've done so far. This is what I want to do:

Since there are two textboxes, two separate search buttons, what I am experiencing is when user selects 1st data for 1st textbox and searchs for 2nd text box then while returning for 1st page after 2nd search, 1st textbox becomes empty, What I want is that it should contain the value user has entered before.

textboxes should keep the value. If searching for 1st text box then 2nd should keep its value and if searching for 2nd text box 1st should keep its value.

I am using response.redirect method in dg_RowCommand event. I think by this page is rendering with its initial values which is what I don't want.

kindly tell me the solution I have searched so much but came up with nothing.

annyyca
  • 13
  • 1
  • 7

4 Answers4

3

You can store the values in either Cookie or in a Session variable. Session variable is application specific and cookies are browser specific.

try this, for creating a session variable

Session["key"] = "your value"

or

for Cookie

Response.Cookies["key"].Value ="your value"

on the another page check first is it not null

if(Session["key"]!=null)
// use it

and same for the cookie (access it with Request object)

if (Request.Cookies["key"] != null)
//  use it
nrsharma
  • 2,532
  • 3
  • 20
  • 36
  • I thought of session varaible but there can be many textboxes so I'll have to store each textbox value in session variable before redirection. I think its cumbersome task to store each and every textbox value. Can't we have better solution? – annyyca Sep 25 '13 at 13:09
  • 1
    you can store those values in a Array and then store that array in a single session variable :) – nrsharma Sep 25 '13 at 13:14
0

use Session variable. Session["YourKey"] = your value; You can access it cross page

Update: If I am right then you are thinking of some wizard type interface. If you can take benefit of ASP.Net Wizard control then look into this. It might help you.

  • I thought of session varaible but there can be many textboxes so I'll have to store each textbox value in session variable before redirection. I think its cumbersome task to store each and every textbox value. Can't we have better solution? – annyyca Sep 25 '13 at 13:10
  • 1
    Well I didn't want wizard like interface. But I am looking upon it, May be it can help – annyyca Sep 25 '13 at 13:20
0

Combine the pages into one, with each page(step) becoming a div or asp:Panel. hide/show divs rather than "navigate to the next page" on Click_Next event (or whatever). This way all controls stay on the same page and maintain all values when the divs are shown/hidden. No Session or other methods needed.

Joe
  • 1,649
  • 12
  • 10
  • No need to down vote because you think the wizard does a better job with steps. It doesn't. And the OP doesn't state how many steps are needed, so hiding a div is reasonable. I've used Wizard before, lots of headaches for little benefit. This is a viable and logical answer. – Joe Sep 25 '13 at 13:55
  • I thought of this exact thing while starting my project and even started doing like this but my boss wants me to navigate to next page and he was reasonable because search thing can be on any page and it's quite general page so can work with any project on with different pages.. using div will require to add this coding to every page I make.. – annyyca Sep 27 '13 at 11:08
-1

If you are redirecting with the Response.Redirect method in the C# Code then before you execute this redirect you can store the items in Session variables:

Session["Test1"] = test1.Text;

Sessions are maintained per user. These will be retained for as long as the application is running, but be warned that if an Application timeout occurs or the user closes the application (closes browser) these values will be lost.

Habib
  • 219,104
  • 29
  • 407
  • 436
Nunners
  • 3,047
  • 13
  • 17
  • storing information in `Application` would result in multiple users sharing same data. See here for [difference between Session, Application and Cache](http://stackoverflow.com/questions/5096544/application-vs-session-vs-cache) – Habib Sep 25 '13 at 12:56
  • Apologies, I confused myself with the `Session` and `Application` items. – Nunners Sep 25 '13 at 12:57