Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · ASP.NET Newsletter Application · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Newsletter
Enter your email address to receive full length articles at Stardeveloper:


Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (41)
  ADO (16)
  ADO.NET (11)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)

Main Category  Other
  Website Maintenance (3)
Log In
UserName Or Email:

Password:

Auto-Login:

Hosted by Securewebs.com
 
Home : .NET : ASP : Extremely useful ASP functions
 
Read full length articles at Stardeveloper using Twitter Follow on Twitter Facebook Facebook fan page Email Get Articles via Email RSS Get Articles via RSS Feed

Extremely useful ASP functions

by Robert Collyer.

Please report any problems found to me ASAP, so I may fix them and build another release. I get literally hundreds of emails asking how to use these functions, and questions relating to them, etc. If you have any enquiries regarding these scripts, email me, but please allow up to 36 Hours for a response.

If you are interested in functions similar to the above but allow interaction with databases, then these will be available soon.

I hope you find these functions to be as useful and time-saving as everyone else, and use them to their fullest potential. I TRULY APPRECIATE ANY FEEDBACK.

The GetVars function, will ONLY work with the VBScripting Engine ver 5.x updates to the scripting engine for win 9x, and NT 4.0 are available from the microsoft site:- www.microsoft.com/scripting.

Bear in mind, I always find it nice to get a mention where my functions are used but I do not require it. I am more willing to help those and supply new updated functions to those who acknowledge me in either content, or comments with the page source.

Good Luck, and Happy Coding!!!

Rob Collyer (aka ASPwiz) ASPwiz@hotmail.com

All of these functions will come into their own when dealing with multiple page forms.

In the Examples given, remember to replace the <$ and $> tags with the proper open/close ASP tags.

Function No.1
This first function will get variables from forms and/or querystrings and/or cookies. The function will set VBScript variables with identical names, and equal values. This saves the tedious task of request.form("this") request.Querystring("that"), and request.cookies("the_other").

Usage:- Call SetVars(StrType) Where 'StrType' is a string value of either, "form", "querystring", "cookies",or "all"

<%
Function SetVars(StrType)
If lcase(StrType) = "form" or lcase(strType) = "all" then
For Each Field in Request.Form
TheString = Field & "=Request.Form(""" _
& Field & """)"
EXECUTE(TheString)
Next
End If

If lcase(StrType) = "querystring" or lcase(strType) = "all" then
For Each Field in Request.Querystring
TheString= Field & "=Request.Querystring(""" _
& Field & """)"
EXECUTE(TheString)
Next
End If

If lcase(StrType) = "cookies" or lcase(strType) = "all" then
For Each Field in Request.Cookies
TheString= Field & "=Request.Cookies(""" _
& Field & """)"
EXECUTE(TheString)
Next
End If
END Function
%>

Function No.2
This second function will get variables from forms and/or querystrings and/or cookies, and write them in a form as hidden fields. This is very useful when dealing with multiple page forms.

The function must be called prior to the </form> tag, so it can include the hidden fields This saves the tedious task of: <Input type="hidden" name="field1" value="value1">, etc This saves a lot of work when passing many, many variables.

Usage:- Call IncludeHidden(StrType, IGNORELIST) Where 'StrType' is a string value of either, "form", "querystring", "cookies", or "all" and 'IGNORELIST' is a comma seperated string of field names to ignore. (Case INsensitive)

EXAMPLE:- To include all values submitted to the page via a form, within the second form as form fields.

<Form Action="Form3.asp" Method="post">
<Input type="text" name="whatever">
<!-- More fields as appropriate-->
<!-- ............ -->

<$ Call IncludeHidden("Form", "") $>
<Input type="submit">
</Form>

If you wanted to exclude a field called 'whatever' (Perhaps the page receives its own data back at some stage). Then you could use:- <$ Call IncludeHidden("Form", "whatever") $> and the hidden form field named 'whatever' won't be included.

<%
Function IncludeHidden(StrType, IGNORELIST)
If lcase(StrType) = "form" or lcase(StrType) = "all" then
For each Field in Request.Form
If NOT Onlist(Field, IGNORELIST) Then
TheString="<Input Type=""HIDDEN"" Name=""" _
& Field & """ Value="""
StrValue=Request.Form(Field)
TheString=TheString + cstr(StrValue) & """>"
TheString=TheString & VbCrLf
Response.Write TheString
End If
Next
End If

If lcase(StrType) = "querystring" or lcase(StrType) = "all" then
For each Field in Request.Querystring
If NOT Onlist(Field, IGNORELIST) Then
TheString="<Input Type=""HIDDEN"" Name=""" _
& Field & """ Value="""
StrValue=Request.Querystring(Field)
TheString=TheString + cstr(StrValue) & """>"
TheString=TheString & VbCrLf
Response.Write TheString
End If
Next
End If

If lcase(StrType) = "cookies" or lcase(StrType) = "all" then
For each Field in Request.Cookies
If NOT Onlist(Field, IGNORELIST) Then
TheString="<Input Type=""HIDDEN"" Name=""" _
& Field & """ Value="""
StrValue=Request.Cookies(Field)
TheString=TheString + cstr(StrValue) & """>"
TheString=TheString & VbCrLf
Response.Write TheString
End If
Next
End If
END Function
%>

Function No.3
This third function will get variables from forms and/or querystrings and/or cookies, and write them in a link as a querystring. This is very useful when dealing with online applications that pass lots of variables this way. The function must be called in a specific way, example given below.

Usage:- Call WriteQueryString(StrType, IGNORELIST) Where 'StrType' is a string value of either, "form", "querystring", "cookies", or "all" and 'IGNORELIST' is a comma seperated string of field names to ignore. (Case INsensitive)

EXAMPLE:- To write all values submitted to the page via a querystring.

<A href="APage.asp?<$Call WriteQueryString("querystring","")$>">
Click Here
</a>

If you wanted to exclude a field for whatever reason, then follow the example as for the 'IncludeHidden' function.

<%
Function WriteQueryString(StrType, IGNORELIST)
If lcase(StrType) = "form" or lcase(StrType) = "all" then
For each Field in Request.Form
If NOT Onlist(Field, IGNORELIST) Then
TheString=TheString+Field&"="
TheString=TheString & Request.Form(Field)
TheString=TheString & "&"
End If
Next
End if

If lcase(StrType) = "querystring" or lcase(StrType) = "all" then
For each Field in Request.Querystring
If NOT Onlist(Field, IGNORELIST) Then
TheString=TheString+Field&"="
TheString=TheString & Request.Querystring(Field)
TheString=TheString & "&"
End If
Next
End if

If lcase(StrType) = "cookies" or lcase(StrType) = "all" then
For each Field in Request.Cookies
If NOT Onlist(Field, IGNORELIST) Then
TheString=TheString+Field&"="
TheString=TheString & Request.Cookies(Field)
TheString=TheString & "&"
End If
Next
End if
If right(TheString,1)="&" Then 
TheString=Left(TheString,Len(TheString)-1)
Response.Write TheString
End if
END Function
%>

 ( 1 Remaining ) Next

Comments/Questions ( Threads: 9, Comments: 16 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. calling function
  2. Need help
  3. Insert Record into access database without submit button
  4. need solution for uploading problem ( 2 Replies )
  5. Populate combo boxes (country and state) by using values from the database ( 2 Replies )
  6. Connecting to SQL Server 2000 Database in ASP ( 1 Reply )
  7. Save multiple files/images into database ( 1 Reply ) This thread contains 1 reply by Faisal Khan.
  8. Support required . ODBC Error found when upload my asp pages ( 1 Reply ) This thread contains 1 reply by Faisal Khan.
  9. Using Multiple CheckBox Updation in Oracle Database

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed.

 
© 1999 - 2010 Stardeveloper.com, All Rights Reserved.