Click here to Skip to main content
15,891,704 members
Please Sign up or sign in to vote.
3.50/5 (2 votes)
See more:
Hi,

In my application i am using two pages,

In the first page having "Drop down list items" and "submit button"

if we click on this button it goes to second page

In the second page having only one button i.e "Cancel button"

if we click on this button it come back to first page.

What i want is in the first page,if we select any of the "drop down list item" then we click on submit button it's goes to second page.

here in second page if we click on "Cancel button" it come back to previous page and maintain the whatever the previous selected value in the drop down list using only "POSTBACKURL".


Please guide me..

Thanks in advance..
Posted
Updated 24-Mar-11 21:08pm
v3

hi,

try history.go-1 funtion of javascript but it browser dependent
or other option is store that value in session in the first Page
check session if it not null
then
ddl.selectedvalue = session["name"]
session["name"] = null
session.clear();
 
Share this answer
 
v2
You have (minimum) 2 options:

1) If you do not need any server side processing after clicking 'Cancel Button', you can use JavaScript and write history.go(-1) onclick of the button. That will take you to the previous page and drop-down-list will show the last selected value.

2) Store the selected value of the drop-down-list in a Session Object and assign the same when you come back to the 1st page after some server side processing on 2nd page. Something like:
C#
Session["DropDownSelVal"] = ddlSomething.SelectedValue;

And on retrival,
C#
ddlSomething.SelectedValue = Session["DropDownSelVal"];


Hope this helps!
 
Share this answer
 
v2
for such scenario,use session
Session["name"]=dropdown.selectedValue;
on page load check the session value
 
Share this answer
 
Just enable viewstate property of Dropdownlist
like:
DropDownList1.EnableViewState = true;  
 
Share this answer
 
v3
Comments
venkatrao palepu 25-Mar-11 3:12am    
Hi Brijesh,

Already i gave EnableViewState="false" for the drop down list .

Still it's not working...

Thanks
venkat
[no name] 25-Mar-11 7:12am    
Yes you are true
actually DropDownList1.EnableViewState = true; works to retain value, but your requirement is little bit different.

For this you have to save your DropDownList selected to a variable and then as the page reloaded, make the text property of dropDownList from that variable.
Ankur\m/ 25-Mar-11 8:07am    
Why are you misguiding OP? The way you suggested in your comment is absolutely wrong.
Get your basics clear.

And I know you down-voted my answer. But that won't change the truth.
Ankur\m/ 25-Mar-11 9:17am    
Okay so you replied from your other id and deleted it. My reputation enables me to still see the comment.
Give a correct way or just don't give it.
Everyone does mistakes. Accepting it and rectifying it is what makes them different.
Ankur\m/ 25-Mar-11 8:08am    
The alternate suggested by the Brijesh Kr below is also wrong. Please see my answer or the answer given by the third responder.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900