31
ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University [email protected]

ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University [email protected]

Embed Size (px)

Citation preview

Page 1: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

ASP/ASP.NET: Tricks and Tips

How to get Microsoft’s Programming Language to work for you

By Wade Tripp

Park University

[email protected]

Page 2: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

DisclaimerI 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.

Page 3: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

Who are YOU?

Page 4: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

History of ASP (abbreviated)

• VBScript– Client Side– Possible for all sorts of problems,

intentional or not– Required the client to have IE installed

Page 5: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

History of ASP (abbreviated)

• ASP– Server Side Scripting– Browser independent– Required special server software

• but…..– Very much interpreted and scripting– Created many bad programming

habits

Page 6: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

History of ASP (abbreviated)

• ASP.NET– Server Side Scripting– Able to program in many languages– Permits good programming practice

• but….– Steep learning curve

Page 7: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

How 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

Page 8: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

How 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

Page 9: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

How 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

Page 10: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

Differences 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

Page 11: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

Differences 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

Page 12: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

Getting down to codeASP/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.

Page 13: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

Simple Displaying StuffTo simply display stuff ( traditionally used in

ASP ) you use <% %>

<% Response.Write ("Hello World") %>

<% = 2 + 2 %>

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.

Page 14: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

Is .asp the same as .aspxNo, 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]

Page 15: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

QueryString vs. FormsThere are two ways to get information.• QueryString/Get

– Information is sent via the URL

• Form/Post– Information sent in the page

Page 16: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

QueryString<form method="GET">

It appears in the URL

.. /index.asp?Sample=test&B1=Submit

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

Page 17: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

QueryString DisadvantagesEasily find the information via History and

guessable test.asp?ID=45

Limited on how much information can be passed. Dependant on browser of 1000, 2000+ characters

Page 18: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

FormWhat is normally used with web pages

<form method="POST">

Better to make things go better and organized, less chance of being reviewed

Page 19: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

Actually using it<%

Dim intNumber as integer

intNumber = Request.QueryString(“Test”)

intNumber = Request.Form(“Test”)

Response.Write (intNumber)

%>

Page 20: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

TIP - Polish NotationBased on ideas of Jan Lukasiewicz

Standard documenting is putting type in front of name

• intName – Integer• strName – String• bolName – Boolean values

Page 21: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

TIP - Polish NotationAlso good for ASP• txtName – Textbox• lblName – Label• panName – Panel• lstName – List

….

It keeps you organized

Page 22: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

Basics of ASP.Net <asp:TextBox id="TextBox1"

runat="server"></asp:TextBox>

When it is transformed by the compiler it becomes

<input name="TextBox1" type="text" id="TextBox1" />

What all happened?

ASP.NET is transformed into HTML

Page 23: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

How does information get storedInformation is stored in a hidden view, called

the Viewstate

It sends and organizes the information for each variable and items

<input type="hidden" name="__VIEWSTATE" value="dDwxMKA0NDg0NTY3Ozs+LbpQGFDDxjwkOEzOioQydd7xkTg=" />

The information is stored for all server objects

Page 24: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

TIP – Don’t make everything label

Each ASP.NET item requires resources

Don’t use labels for standard items.

Why?

Because it takes extra resources and time to download

Page 25: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

TIP – Don’t make everything label

Each ASP.NET item requires resources

Don’t use labels for standard items.

Why?

Because it takes extra resources and time to download

Page 26: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

TRICKS – Storing informationInformation can be handled• Session• Application• Variable• Value of ASP Object• Hidden Field• Passed Variable in Form

Page 27: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

TRICKS – Database ReadingCan connect to database via connection with

SQL, Access, Informix, etc… anything that permits ODBC

Warning – Access can cause problems with older web servers

Page 28: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

TRICKS – AutoPostbackPermits scripting to run after an item has been

altered

Requires Javascript

Page 29: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

TRICKS – ValidationLets 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)

Page 30: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

TRICKS – Smart NavigationPermits forms not to blink by using ‘IFRAME’

Page 31: ASP/ASP.NET: Tricks and Tips How to get Microsoft’s Programming Language to work for you By Wade Tripp Park University wtripp@mail.park.edu

TRICKS – ME - ASPUsed to find what variables and objects are

used

Remove the Me. after you go though the form