Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET
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 24-Mar-11 21:06pm
Edited 24-Mar-11 21:08pm
v3
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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();
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

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:
Session["DropDownSelVal"] = ddlSomething.SelectedValue;
And on retrival,
ddlSomething.SelectedValue = Session["DropDownSelVal"];
 
Hope this helps!
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Just enable viewstate property of Dropdownlist
like:
DropDownList1.EnableViewState = true;  
  Permalink  
v3
Comments
venkatrao palepu at 25-Mar-11 3:12am
   
Hi Brijesh,
 
Already i gave EnableViewState="false" for the drop down list .
 
Still it's not working...
 
Thanks
venkat
Brijesh Kr at 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/ at 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/ at 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/ at 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.
Ankur\m/ at 25-Mar-11 3:15am
   
And why do you think that will do the job? Http is a stateless protocol and every postback will cause the page to be created once again.
venkatrao palepu at 31-Mar-11 2:33am
   
Hi,
 
Thanks for your suggestions,
 
i got this solution using Hidden Fields.
 
Thanks a lot for your cooperation.
 
Thanks
venkat
Brijesh Kr at 31-Mar-11 7:06am
   
You're Most Welcome
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

for such scenario,use session
Session["name"]=dropdown.selectedValue;
on page load check the session value
  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 353
1 OriginalGriff 304
2 George Jonsson 258
3 Shemeemsha RA 138
4 Animesh Datta 130
0 OriginalGriff 5,985
1 Sergey Alexandrovich Kryukov 5,341
2 CPallini 4,760
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web02 | 2.8.140916.1 | Last Updated 31 Mar 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100