Developing Web Application with ASP.NET and C#
By Hank Meyne, Scott Davis
Overall: ASP .NET is compiled code and running Common Language Runtime. It is truly Object Oriented. It could access the whole Windows System. It has proper error handling. Server-Side controls. It also has state in non-state environment and it is event driven programming.
Anatomy of ASP.NET
<form runat=server> it will generate the hidden input: __VIEWSTATE
<asp:Label>
<asp:Button>
System.Web.UI.Page is the base class of ASP.NET page. .NET package name’s first letter is Capticalized.
ILDASM.exe to view the .NET MSIL code. (System.Web.dll)
Init – Page_Init _Load (attribute PostBack) Unload. _DataBinding, _PreRender _Dispose. _Error
WebForm1.aspx – WebForm1.aspx.cs
<%@ Page language=”C#” Codebehind=” WebForm1.aspx.cs”, AutoEventWireup=”false” Inherits=”Chapter2.WrebForm1” %?=> . Codebehind means that base class to be inherited if you have in-line script.
CSC.exe is c-sharp compiler and it will generate .NET assembly and JITed to the x86 native code.
“web.config” <compilation>
- Web Server Controls (System.Web.UI.WebControls): Lable, Button, LinkButton, Image, ImageButton, HyperLink, TextBox, Check Box, RodioButton, DropDownList, ListBox, CheckBoxList, RidioButtonList, Panel, Table, (TableRow, TableCell), and DataGrid.
- HTML Server Controls (System.Web.UI.HTMLControls): add form runat=server means any HTML is accessible from the server side.
- ValidationControl (System.Web.UI.Validation). RequiredFieldValidator, RegularExpressionValidator, ValidationSummary, RangeValidator, CompareValidator, CustomValidator (id_ServerValidate)
__doPostBack
<%# %> refers to data binding
Database Access ADO.NET
System.Data.SqlClient Connection, DataSet, Command, DataAdaptor, DataReader (forward only)
System.Web.SessionState
Session.Add(“name”, object). Session[“name”] = object.
Global.asax is the
.ascx file is the ASP.NET Custom Control file.
<%@ Register TagPrefix=”uc1” TagName=”UCCalendar” Src=”UCCalendar.ascx” %>
Chapter 6
Creating more advanced ASP.NET pages
We have seen how to use Web Server Controls and the event-driven programming model that is now available in ASP.NET. We’ve covered database access and how we can bind our server-side controls to various data sources. We’ve also covered the very useful code-behind programming methodology that allows us to separate the code that makes our page work and the code that makes up user interface.
In this chapter, we’ll introduce some more advanced concepts to build on what we already know. We’ll cover the HttpRequest, HttpResponse objects, and Cookes and see how we can provide greater customization of client sessions and remember users between visits to our sites. We’ll also see how we can store our own information in the client’s ViewState and store objects in memory on the server-side with Session and Application variables.
Wilson.MasterPages
Web.Config
<appSettings>
<add key="Wilson.MasterPages.DefaultContent" value="mpMainContent" />
<add key="Wilson.MasterPages.TemplateFile" value="~/MainBasicMaster.ascx" />
System.Configuration.ConfigurationSettings.AppSettings[“dsn”]
http://www.microsoft.com/japan/msdn/net/aspnet/aspnet-standardize-masterpages.aspx
http://weblogs.asp.net/pwilson/archive/2004/04/13/112184.aspx
Global.asax: HttpApplication Object is related to this file.
- Application_Start
- Application_End
- Session_Start
- Session_End
- Application_BeginRequest
- Application_EndRequest
Application Variables are those that are stored on the server and available to all code in the an entire ASP.NET application. This is analogous to a global variable, but used across multiple clients, instead of multiple code modules or windows.
Application[“blah”]
Session is using cookie to store a sessionID. It should have section in the Web.Config to enable Session.
Session[“blah”]
ViewState variables is not kept in the server and has nothing to do with session. Instead, it uses the built-in ViewState mechanism of ASP.Net to store string type date in the hidden View state variables in the browser.
ViewState[“blah”]
Page Subclassing is based on the OO design of the basepage which inherits System.Web.UI.Page.
User Controls provide the ability to reuse user interface code across multiple pages. They provide a simple way to combine multiple Web or HTMl server controls into a reusable web form element that can be place on multiple pages. Navigational or menu bars that are used consistently throughout a web application are prime candidates to be converted to a user control. Prior to ASP.NET this sort of code reuse would have been done through the use of server-side include.
Tony
No comments:
Post a Comment