Title: ASP'net Tips and Tricks
1ASP/ASP.NET Tricks and Tips
How to get Microsofts Programming Language to
work for you By Wade Tripp Park
University wtripp_at_mail.park.edu
2Disclaimer
- I am not an expert in all the details, just
giving a general overview of how it works, and
there are over a dozen ways how to do things,
with half of them working.
3Who are YOU?
4History of ASP (abbreviated)
- VBScript
- Client Side
- Possible for all sorts of problems, intentional
or not - Required the client to have IE installed
5History of ASP (abbreviated)
- ASP
- Server Side Scripting
- Browser independent
- Required special server software
- but..
- Very much interpreted and scripting
- Created many bad programming habits
6History of ASP (abbreviated)
- ASP.NET
- Server Side Scripting
- Able to program in many languages
- Permits good programming practice
- but.
- Steep learning curve
7How ASP works
- Browser requests a web page
- Web server gets request and loads file from hard
drive - Web server sends the file to asp.dll to process
- Returns to the browser the processed page
8How ASP.NET works (interpreted)
- Browser requests a web page
- Web server gets request and loads the file from
hard drive - Web server sends the file to aspnet_isapi.dll to
process - Returns to the browser the processed page
9How ASP.NET works (compiled)
- Browser requests a web page
- Web server gets request and loads dll from hard
drive - Web server sends the file to aspnet_isapi.dll to
process - Returns to the browser the processed page
- The code does not have to be on the server
10Differences between ASP
- ASP
- Quick and easy to use and do
- Easy to modify and tweak
- Uses the very basics and forgiving
ASP.NET (Interpreted) Increased flexibility No
need to code everything from scratch Memory of
events Still can get confusing for large projects
ASP.NET (Compiled) Most flexible Hardest to
understand Easy to get good programming standards
11Differences between ASP
- Simple and quick ASP
- Ex Date modified, Alert Message
Repeated on several pages ASP.NET Interpreted
Ex Announcement on several web pages
Advanced Application ASP.NET Compiled Ex
Registration form
12Getting down to code
- ASP/ASP.NET handles the appearance, input/output
of a web page - The Code Behind focuses on the thinking and
language - Code Behind can happen in a web page itself and
does not have to be in a .vb or .cs file - Any language can use in theory, VB and C are the
ones Microsoft has preconnected in Visual Studio,
but almost any can be used. Java is not used for
various legal reasons.
13Simple Displaying Stuff
- To simply display stuff ( traditionally used in
ASP ) you use lt gt - lt Response.Write ("Hello World") gt
- lt 2 2 gt
- ASP is forgiving, so if you miss the ( ) in
Response.Write, it has variant type and other
items. But if you save it as .aspx it may not
work.
14Is .asp the same as .aspx
- No, but they are so close that most of the time
you can just do minor changes and tweaks going
from asp to aspx . Several things are required
(Declaration of variables) - The big change with CDONTS. The method for
sending out mail was changed from ASP to ASP.NET
IIS 5 to IIS 6 for various reasons Security
being the main one
15QueryString vs. Forms
- There are two ways to get information.
- QueryString/Get
- Information is sent via the URL
- Form/Post
- Information sent in the page
16QueryString
- ltform method"GET"gt
- It appears in the URL
- .. /index.asp?SampletestB1Submit
- The ? Marks the end of the URL and the rest are
variables - Items are recoded for valid characters (make
spaces into , turned into 26 and other items) - Advantage jump directly to section, performing
items
17QueryString Disadvantages
- Easily find the information via History and
guessable test.asp?ID45 - Limited on how much information can be passed.
Dependant on browser of 1000, 2000 characters
18Form
- What is normally used with web pages
- ltform method"POST"gt
- Better to make things go better and organized,
less chance of being reviewed
19Actually using it
- lt
- Dim intNumber as integer
- intNumber Request.QueryString(Test)
- intNumber Request.Form(Test)
- Response.Write (intNumber)
- gt
20TIP - Polish Notation
- Based on ideas of Jan Lukasiewicz
- Standard documenting is putting type in front of
name - intName Integer
- strName String
- bolName Boolean values
21TIP - Polish Notation
- Also good for ASP
- txtName Textbox
- lblName Label
- panName Panel
- lstName List
- .
- It keeps you organized
22Basics of ASP.Net
- ltaspTextBox id"TextBox1" runat"server"gtlt/aspTe
xtBoxgt - When it is transformed by the compiler it becomes
- ltinput name"TextBox1" type"text" id"TextBox1"
/gt - What all happened?
- ASP.NET is transformed into HTML
23How does information get stored
- Information is stored in a hidden view, called
the Viewstate - It sends and organizes the information for each
variable and items - ltinput type"hidden" name"__VIEWSTATE"
value"dDwxMKA0NDg0NTY3OzsLbpQGFDDxjwkOEzOioQydd7
xkTg" /gt - The information is stored for all server objects
24TIP Dont make everything label
- Each ASP.NET item requires resources
- Dont use labels for standard items.
- Why?
- Because it takes extra resources and time to
download
25TIP Dont make everything label
- Each ASP.NET item requires resources
- Dont use labels for standard items.
- Why?
- Because it takes extra resources and time to
download
26TRICKS Storing information
- Information can be handled
- Session
- Application
- Variable
- Value of ASP Object
- Hidden Field
- Passed Variable in Form
27TRICKS Database Reading
- Can connect to database via connection with SQL,
Access, Informix, etc anything that permits ODBC - Warning Access can cause problems with older
web servers
28TRICKS AutoPostback
- Permits scripting to run after an item has been
altered - Requires Javascript
29TRICKS Validation
- Lets a user check to make sure a field is
probably filled out - Normally uses Javascript to validate
- There are a few ways around it (disable
Javascript)
30TRICKS Smart Navigation
- Permits forms not to blink by using IFRAME
31TRICKS ME - ASP
- Used to find what variables and objects are used
- Remove the Me. after you go though the form