Click here to Skip to main content
11,813,974 members (61,651 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET

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
Rate this: bad
Please Sign up or sign in to vote.

Solution 2


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
ddl.selectedvalue = session["name"]
session["name"] = null
Rate this: bad
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!
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

for such scenario,use session
on page load check the session value
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Just enable viewstate property of Dropdownlist
DropDownList1.EnableViewState = true;  
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...

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

Thanks for your suggestions,

i got this solution using Hidden Fields.

Thanks a lot for your cooperation.

Brijesh Kr at 31-Mar-11 7:06am
You're Most Welcome

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

  Print Answers RSS
0 Abhinav S 265
1 Sergey Alexandrovich Kryukov 219
2 Maciej Los 218
3 Palash Mondal_ 190
0 OriginalGriff 3,877
1 KrunalRohit 2,526
2 Maciej Los 2,245
3 CPallini 2,240
4 ppolymorphe 1,750

Advertise | Privacy | Mobile
Web01 | 2.8.151002.1 | Last Updated 31 Mar 2011
Copyright © CodeProject, 1999-2015
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