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 Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Barrage of hopefully easy beginner questions 1

Status
Not open for further replies.

pigsie

Programmer
Dec 19, 2000
307
GB
Hi

I have a few beginner questions so i thought i would group them all together instead flooding the list with emails. I have used other scripting langauges but am making a transition to asp. Could anyone help me with these hopefully easy questions? Thanks:

1. How can i check if a variable exists

2. How can i check if a form field exists or a variable passed on the url

3. What is the best way to redirect a user to another page

4. Can recordsets be cached in anyone (perhaps storing them in the session/application) is this a good idea? WIll it harm performance?

5. Are sessions still reliant on cookies or are there other alternatives?

6. Is there a way to stop execution of the page so only what has been processed so far will be displayed

7. How can i create a secure section of my site?

Many many thanks in advance and yes i will be picking up some books.

Pigsie
 
1. How can i check if a variable exists
Write it to the page. Response.Write() or msgbox()
example
Dim Var1
Var1 = "hello!"
'test variable
Response.Write Var1
MsgBox=(Var1)


2. How can i check if a form field exists or a variable passed on the url
Again, Write it to the page. Response.Write() or msgbox()

3. What is the best way to redirect a user to another page
URL = "Response.Redirect(URL)

4. Can recordsets be cached in anyone (perhaps storing them in the session/application) is this a good idea? WIll it harm performance?
Yes!!
For security questions read this

5. Are sessions still reliant on cookies or are there other alternatives?
Not sure what you mean...you really have no need to use cookies with asp but you can. The main purpose of cookies was to do things you were unable to with client side code. I'm sure there's going to be a lot of disagreeing with that one, but you can do just about everything in asp without having the use of cookies.

6. Is there a way to stop execution of the page so only what has been processed so far will be displayed
Either script timeout
Or exit Sub and then do your displaying

7. How can i create a secure section of my site?
Do you mean login access only? Use a database with the user names and passwords for access. Have a form to login and then search teh database (SELECT if [form field] = rs.USERID etc.
If it fails redirect

hope that helps out [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
2. How can i check if a form field exists or a variable passed on the url
===========For Forms==============
dim x

x = Request.Form("variableName")
Response.Write x
==================================


======For variable in the url===========
dim x

x = Request.QueryString("variableName")
Response.Write x
========================================
 
Hi thanks for the replies, i didnt mean check if a variable exists for debugging purposes i mean for example to check that a form correctly submmited fields (some browser bugs will drop fields occasionally on mac)

As for sessions and cookies, what i meant was how does the server associate one client request from another.

The secure section i was refering to was a password protected section as onpnt guessed. The thing is once the user logs in if i use a session variable do i need to check that the user is logged in at the start of every page?

Thanks guys
 
for the log in. Yes! just check for it to be True.

mithrilhall, got the checking for the submission of the form values.

I'm still a little confused on the session and cookies question. The server will determine the difference for what cookies you set to the clients computer. straighten me out on what you need!! [bomb]
I may not get it the 1st or 2nd time,
but how sweet that 15th time can be.
admin@onpntwebdesigns.com
 
To continue:

2. How can i check if a form field exists or a variable passed on the url
dim str_String, lng_LongNumber
str_String = Request.Form("thestring")
lng_LongNumber = Request.Form("thenumber")
if len(str_String) > 0 then
'it exists
end if
if len(lng_LongNumber) > 0 then
'it exists
if isnumeric(lng_LongNumber) then
'it's also numeric
lng_LongNumber = clng(lng_LongNumber)
'and now it's converted into a number
end if
end if
(obviously to check querystring replace Form with QueryString)

3. What is the best way to redirect a user to another page
* Response.Rediect is the simplest, but it requires sending a message to the client browser to tell it to request the new page from the server.
* Server.Transfer (IIS only) moves execution to the new page with no memory of variables from the old page (although it does retain Form/QueryString values)
* Server.Execute is like Server.Transfer (also I believe IIS only) but it returns execution to the calling page once it's complete. It has no memory of variables on the calling page when it executes the 'sub' page, and when execution returns to the calling page there is no memory of variables from the called page (tho there IS memory of the variables on the calling page set prior to the Execute call). Did you get that ? :p

4. Can recordsets be cached in anyone (perhaps storing them in the session/application) is this a good idea? WIll it harm performance?
Debatable topic. Personally I NEVER store objects (or anything else for that matter) in IIS. I use client cookies for DB generated GUIDs for sessions, and all else is stored in the database.
It will probably only harm performance noticably if your site will take a LOT of hits simultaneously, OR if you store LARGE recordsets in the Session/Application objects.

5. Are sessions still reliant on cookies or are there other alternatives?
To my knowledge IIS stores Session/Application details in Server-Side cookies, and can only do this.

6. Is there a way to stop execution of the page so only what has been processed so far will be displayed
* Response.End stops execution. Full stop. The End.
(Often you'll call Response.write or Response.Flush prior to this for debugging purposes).
* Related: Response.IsClientConnected checks - guess what?
(Good for use before large and potentially pointless processing blocks).

codestorm
Fire bad. Tree pretty. - Buffy
select * from population where talent > 'average'
You're not a complete programmer unless you know how to guess.
<insert witticism here>
 
Thanks thats just what i wanted to know in exactly the right amount of detail. thanks for all replies.

Regarding the cookies/session as far as i could remember underneath asp sets a browser session cookie in order to tell the difference between 2 client requests is this true?

I'm sure if i remember correclty that if the user has cookies off you cannot use session?

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top