310 likes | 488 Views
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. Disclaimer.
E N D
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
Disclaimer 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.
History of ASP (abbreviated) • VBScript • Client Side • Possible for all sorts of problems, intentional or not • Required the client to have IE installed
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
History of ASP (abbreviated) • ASP.NET • Server Side Scripting • Able to program in many languages • Permits good programming practice • but…. • Steep learning curve
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
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
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
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 Differences between ASP
Simple and quick – ASP Ex – Date modified, Alert Message Differences between ASP Repeated on several pages – ASP.NET Interpreted Ex – Announcement on several web pages Advanced Application – ASP.NET Compiled Ex – Registration form
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. Getting down to code
To 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. Simple Displaying Stuff
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] Is .asp the same as .aspx
There are two ways to get information. QueryString/Get Information is sent via the URL Form/Post Information sent in the page QueryString vs. Forms
<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 QueryString
Easily 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 QueryString Disadvantages
What is normally used with web pages <form method="POST"> Better to make things go better and organized, less chance of being reviewed Form
<% Dim intNumber as integer intNumber = Request.QueryString(“Test”) intNumber = Request.Form(“Test”) Response.Write (intNumber) %> Actually using it
Based on ideas of Jan Lukasiewicz Standard documenting is putting type in front of name intName – Integer strName – String bolName – Boolean values TIP - Polish Notation
Also good for ASP txtName – Textbox lblName – Label panName – Panel lstName – List …. It keeps you organized TIP - Polish Notation
<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 Basics of ASP.Net
Information 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 How does information get stored
Each ASP.NET item requires resources Don’t use labels for standard items. Why? Because it takes extra resources and time to download 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 TIP – Don’t make everything label
Information can be handled Session Application Variable Value of ASP Object Hidden Field Passed Variable in Form TRICKS – Storing information
Can connect to database via connection with SQL, Access, Informix, etc… anything that permits ODBC Warning – Access can cause problems with older web servers TRICKS – Database Reading
Permits scripting to run after an item has been altered Requires Javascript TRICKS – AutoPostback
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) TRICKS – Validation
Permits forms not to blink by using ‘IFRAME’ TRICKS – Smart Navigation
Used to find what variables and objects are used Remove the Me. after you go though the form TRICKS – ME - ASP