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!

Maintaining ViewState without .NET

Status
Not open for further replies.

rudejohn

IS-IT--Management
Jul 11, 2003
130
US
I am new to ASP, I have a VERY limited ASP.NET experience, but now the server I am working on is not dot-NET capable.

The user is using HTML SELECT/OPTIONs to determine a start and end date. The values from this SELECT are being used to dynamically generate a SQL query, and then the page calls itself and redraws a table.

I want the options which were selected when the user pressed the button to STILL be selected when (s)he returns. So, for example, if you choose the range 7/10/2003 to 7/12/2003 in the drop-down boxes, I want those dates to STILL be displayed in the drop-down box when the user returns.

I know that in .NET you can use ViewState but have been unable to make that code work in regular VBScript in ASP.

If there is a simple solution, that would be great. I checked BOL and the FAQ for this forum, but was unable to find anything of use.

The only solution I can think of is to do a check at the start of the page, and a SELECT statement. If the SELECT statement finds 7/10/2003, for example, it checks a flag variable. Then, when I generate the HTML for the user, I cycle through and have something like:

<OPTION value=&quot;7/10/2003&quot; selected=&quot;<%=flag4%>&quot;>blah</OPTION>

Where the flags are set to &quot;false&quot; by default, and set to &quot;true&quot; in that one case.

I'm trying this but getting some bugs... if someone has a simpler solution I would appreciate it...

RJ


************
RudeJohn
************
 
You've got the right idea, but the execution is slightly off. The SELECTED attribute of the OPTION aggregate in HTML does not have the ability the have a value set to it - that it, it's more of a switch than a value holder. So, assuming that you've got different flags for each OPTION aggregate, you'd want your code to look something more like this:

[tt]
<%
If Not flag4 Then '// this option was not selected
%>
<OPTION value=&quot;7/10/2003&quot;>blah</OPTION>
<%
Else '// this option was selected
%>
<OPTION value=&quot;7/10/2003&quot; SELECTED>blah</OPTION>
<%
End If
%>
[/tt]

That's not necessarily the most efficient way to do it - for example, I'd be building my HTML code in ASP, setting it ot string variables, and then writing out those string variables - but this gives you the idea of what to do.

HTH,
jp
 
Hrmmm, I tried my best to find it, but was unable... I was in a thread awhile back in which someone claimed that XHTML is going to depreciate the use of:
<OPTION value=&quot;x&quot; SELECTED>
in favor of
<OPTION value=&quot;x&quot; selected=&quot;true&quot;>
I know that the former will work currently, but if you look at it from W3's perspective, you should always have parameter=value as the syntax...
Which is why I had tried my original solution. Perhaps it was selected=&quot;selected&quot;... I'll try that and get back to you, in the meantime any other thoughts?

************
RudeJohn
************
 
This works as expected (second item is selected) in IE 6 and Mozilla on Win2k

Code:
<select>
<option value=&quot;1&quot;>One</option>
<option value=&quot;2&quot; selected=&quot;true&quot;>Two</option>
<option value=&quot;3&quot;>Three</option>
</select>

-pete
 
Only thing I can think of, RJ, is that VBScript loves to capitalize the string representations of boolean values when converting them in a Response.Write. I would try:

[tt]<OPTION value=&quot;7/10/2003&quot; selected=&quot;<%=lcase(cstr(flag4))%>&quot;>blah</OPTION>[/tt]

I'm not currently up on my W3 standards for XHTML, but maybe the selected attribute is case-sensitive? Worth a shot, I guess.

Let us know how it goes.

HTH,
jp
 
I defer to you, jpbrassard. I changed it to work like this (just to avoid all the &quot;if&quot; statements; there are like 20 OPTIONS in the list):

<OPTION value=&quot;1&quot; <%=flag1%>>1</OPTION>

I made the &quot;flag&quot; variables strings instead of Boolean, and have their values equal to &quot;&quot; or &quot;SELECTED&quot; :)

Yes, it's slightly ghetto and sloppy, but it works. Thanks for all your help and input, and have a nice day.

~RJ

************
RudeJohn
************
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top