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!

Run Different Code When Page is First Opened 1

Status
Not open for further replies.

DebbieC

Programmer
Mar 29, 2001
168
US
I have a page that has two date fields (for a date range) and a drop down list.

When the page is opened, it defaults to a date range of the last 30 days. The drop down list defaults to "All" so it lists all records for the last month.

The user can change the dates and/or the specific Jurisdiction, select the "Go" button and get a new list.

The only way I could think of to determine if the page was just opened is to check to see if the drop down list has a value. However if they change the dates but don't change the drop down list then it defaults back to the 30 day range.

How else can I determine whether the page is first opened to run some default code?

Here's the code I have:

If JurID = "" then
sDate = DateAdd("m",-1,Now())
StartDate = FormatDateTime(sDate,2)
EndDate = Month(Now) & "/" & Day(Now) & "/" & Year(Now)
sql = " WHERE DateReceived BETWEEN '" & StartDate & "' AND '" & EndDate & "' ORDER BY DateReceived DESC "
else
StartDate = Request("StartDate")
EndDate = Request("EndDate")

sql = " WHERE JurID=" & JurID & " AND DateReceived BETWEEN '" & StartDate & "' AND '" & EndDate & "' ORDER BY DateReceived DESC "
JurID = clng(JurID)
end if


Thanks!
 
Perhaps a session variable would help

or you could use a cookie file to make a count and then check to see if current count is greater than one

add this to a page or your global.asa file
Code:
Response.Cookies("Yourcookie").expires = Date + 1
Response.Cookies("Yourcookie")("numberofloads")=0
then this to the page in question
Code:
avariable = Request.Cookies("Yourcookie")("numberofloads")
Response.Cookies("Yourcookie")("numberofloads")= avariable + 1

YourCount= Request.Cookies("Yourcookie")("numberofloads")
If YourCount = 1 Then 
'Yourcodehere
Else
Response.Write""
End If
 
Now that I think of it it would probanly be a little easier if you just used session variables
 
I thought that's the way I should do it. I've never used session variables so I will have to do some research to see how to do it.


Thanks.
 
If they are hitting a button, the page is then a postback, no?

Code:
Dim isPostBack
isPostBack = uCase(Request.ServerVariables("REQUEST_METHOD")) = "POST"

If is PostBack Then
    'Page has been posted
Else
    'Page has not been posted
End IF
 
oops that should read

If [highlight]isPostBack[/highlight] Then
'Page has been posted
Else
'Page has not been posted
End IF
 
JSpicolli --

So let's assume the ServerVariables("REQUEST_METHOD") has a value of "POST", then your line of code would effectively read:
Code:
isPostBack = "POST" = "POST"

Maybe I'm just not seeing something, but what does that line do? Other than maybe error out?
 
No, you are way off.

Code:
uCase(Request.ServerVariables("REQUEST_METHOD")) = "POST"

Will return a boolean, either true if it matches, or false if it does not.

Basically, my one line of code is the same as:

Code:
If (uCase(Request.ServerVariables("REQUEST_METHOD")) = "POST") = True Then
  isPostBack = true
Else
  isPostBack = false
End If

 
At least for the sake of clarity, I'd use parentheses around the conditional:

isPostBack = [red]([/red]uCase(Request.ServerVariables("REQUEST_METHOD")) = "POST"[red])[/red]

Lee
 
Ethorn10,

The most basic operator is the equality operator (in VBScript it is = )
Which will compare 2 values of the same type, and return a boolean

Consider this Code:
Code:
<% 
	Dim Age1, Age2, Age3
	Age1 = 34
	Age2 = 35
	Age3 = 34
	
	
	%>
<%= Age1 = Age2 %>
<BR>
<%= Age1 = Age3 %>

 
Ok. I didn't suspect that I was right, mainly just curious. I just haven't seen it handled that way. Sorry to question, but I learned something new...
 
Perhaps I should. Or maybe I'll just ask questions when I see something different. .

Wow.
 
ethorn10

great, I love learning new things.

If you can understand operand operations, you will save yourself alot of time and conditional coding.
 
Since VBScript uses the single equals sign for both assignment and comparison, it'd be clearer if you did use an If statement to avoid ambiguity. In some programming languages, you can do multiple assignments using what jspicolli showed.

Lee
 
Right, but in those cases the assignment and comparison operators are different.

Typically, I agree readabilty trumps shorthand.

That said, in this specific case, I think it is fairly self-evident what is happening (as long as you wrap the entire operation in parens).
 
Wow! Lots of suggestions. Thanks for all of them.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top