Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retain the value of dropdownboxes after refresh 1

Status
Not open for further replies.

JDAEMS

Programmer
Aug 27, 2003
84
BE
Dear sir/madam,

I have a web page with different textboxes and dropdownboxes on them. When a user double-clicks a dropdown box, he will get a pop-up screen giving him the possibility to search and select items.

After he presses OK on the popup window, the original screen gets refreshed and the chosen item is written to the textbox.

Now this all works fine, but the problem I am having is that if I make choices in the dropdownboxes, then those choices are reset after refreshing that page. So all of my choices are undone. How can I prevent this from happening?

Kind regards
Jelle
 
Is the code that populates the dropdowns in page_load and and are you checking for a postback?

If not ispostback then
...populate ddls...
end if
 
Yes, I am. It is in the load procedure and I do have a check on the postback:

<code>
If Page.IsPostBack = False Then
cboReport.Items.Add(New ListItem("Report1", "1"))
cboReport.Items.Add(New ListItem("Report2", "2"))
End If
</code>

Now, I thought that this should do it. But still my selections are not remembered.

 
There isn't anything wrong with the code you've provided (and if you copy it into a new page, add a DropDownList named "cboReport", add a Button to the page and your code to the Page Load event, you'll see that it works fine). So, it is either that ViewState isn't enabled on the page or you have other code interfering with it.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Well, I'm not doing anything else than just making a selection in one of the boxes and then pushing the refresh button on my browser. And then my selections are lost.

The enableviewstate is put standard to true for all my selection boxes, so I wouldn't know why it doesn't remember my choices.
 
and then pushing the refresh button on my browser
There's the problem then. You aren't posting the page so there is nothing to remember.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Ok, so now I have put the autopostback on true for the dropdownboxes and now it works.

But the disadvatage is that every time I refresh I get a message box telling me that the page cannot be refreshed without resending the information. And then i have to click retry or cancel.

Is there a way that this can be avoided. I do not want the users having to click on the retry-button every time?
 
Well, if you double-click on one of the textboxes on the page, a new page opens up as a pop-up. in this new page you can search and select items. When you press ok on this new page, the following happens:
- The selected items are stored in a session variable
- The current window closes
- The original window gets refreshed and in it's load procedure I check the session variable. When it is not empty, I count the number of items that are in it and I write "4 items added" into the textbox.

And that is the reason why I need to refresh. I cannot think of another way of doing this.
 
The original window gets refreshed
And how are you doing this? Through code (and if so what code are you using) or are you asking the user to click the refresh button?


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
The finish button on the pop-up window has the follwoing code behind it:

<code>
'First there is some code to retrieve the selected items out of the listbox and put them into the session variable

script = "<script type=""text/javascript"" > "
script += "window.opener.document.location.reload();"
script += "window.close();"
script += "</script>"
Page.RegisterClientScriptBlock("RefreshAndClose", script)
</code>

And then it will refresh the orinil page resulting in that messagebox that comes first.
 
Thank you for all your replies so far. i really appreciate your help.

I have changed my code into this:

<code>
script = "<script type=""text/javascript"" > "
script += "window.opener.document.location = window.opener.document.location;"
script += "</script>"
Page.RegisterClientScriptBlock("RefreshAndClose", script)
</code>

Ok, that seems to solve the problem of the messagebox. But when doing it like this, then you lose the selection you have previously made on the original page.

So on the original page there are textboxes and selection boxes. You make a selection in the boxes, you double-click on a text box, which opens up a popup-window, in which you search and select item, you press Finish and you get back to your orinigal page, but the selection you have made are gone.

Kind regards
Jelle
 
There are various ways around this. You could:

1) pass the values back as a querystring and then set the selections
2) use an ajax method to refresh the relevant part of the field
3) use javascript to work out the number of items added

#3 will probably be the easiest as it negates the need for t a postback/refresh.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top