Web Form Fundamentals Chapter-2 Unit-2
Problem with Response. Write Spaghetti code When the individual output is to be modified the entire code is to be revised Lack of flexibility Modification of the page after a month, the entire code needs to be read and later modified Confusing content and formatting Difficulty in creating larger forms
Problem with Response. Write Complexity Tracking of different types of functionalities leads to complexity
Server Controls ASP.NET provides two sets of Server Controls HTML Server Controls Contains equivalent HTML elements Use similar HTML tags Web Controls Similar to HTML controls Provide a richer object set Variety of properties and formatting
Features of HTML control They generate their own interface The properties are set and the underlying HTML tag is updated automatically when the page is rendered and sent to the client They retain their state The web pages can be created in the same way as the windows page is created
Features of HTML control They fire events You can respond to these events just like ordinary controls in windows application
The ViewState Traditional ASP A form is submitted to the server with the filled information The Server returns back with error All the information's are lost when is page is viewed by the user
The ViewState The ASP.NET The form is submitted to the server with information The server returns the page back with error Now the page contains the information that was given at the time the page was sent to the server HOW? This is because ASP.NET maintains the viewstate
The ViewState The ViewState indicates the status of the page when submitted to the server The Status is defined through the hidden field placed on each page with a tag, the hidden fields stores information about the state Maintaining the ViewState is the default setting of the ASP.NET If you do not want to maintain the ViewState include the directive
The HTML control class The HTML server controls are available in the namespace System.Web.UI.HtmlControls
The HTML control class Class NameTag HtmlAnchor HtmlButton HtmlForm HtmlImage HtmlInputButton,
The HTML control class HtmlInputCheckbox HtmlInputControl HtmlInputFile HtmlInputHidden HtmlInputRadioButton HtmlSelect
Events Web forms are event driven means every piece of code acts in response to the specific event The HtmlButtonClass provides the Server Click event
Events Imports statement It provides access to all the important namespace Custom Page class and control variables Single event handler This event handler retrieves the value from the textbox and converts it into the respected conversion
Event handling changes Two parameters (source and e) Recommended standard for.NET It allows your code to identify the controls that sent the event Private sub convert_Serverclick(sender As Object,e as EventArgs)_ Handles convert.ServerClick
Event handling changes Second the event handler connects itself to the appropriate event using the handles clause AutoEventWireup is set to “false” so that the ASP.NET will always rely on the Handles keyword to connect to the event handlers <input type=“submit” value=“Ok” id=“convert” OnServerClick=“Convert_ServerClick” runat=“server”>
HtmlControl Classes Every html control inherits from the base class HtmlControl HtmlControl Events –ServerClick - Click is processed on the server side –ServerChange - This event reponds when a change has been made to a text or selection control
Events and Controls that provide it EventsControls that provide it ServerClickHtmlAnchor,Form,Button, InputButton,InputImage ServerChangeText,InputCheckBox, RadioButton,Select
HtmlInputImage control Click the image and the co-ordinates are to be displayed
HtmlControlBase Class Each Html control inherits from the base class HtmlControl
HtmlControl Base class PropertyDescription AttributesProvides a collection of all tag attributes and their values ControlProvides the collection of control available under current control DisabledTrue Disables the control and the user cannot interact EnableViewState True:It uses the hidden field to store the information about the page
HtmlControl Base class PropertyDescription PageProvides a reference to the web page that contains the control StyleCSS style properties that can be used to format Tag NameIndicates the name of the Html element VisibleFalse:The control is hidden from the user
HtmlContainerControl class Any html control that requires a opening and closing tag also inherits from the HtmlContainer Control - HtmlAnchor - HtmlForm - HtmlGeneric Control
HtmlContainerControl class PropertyDescription InnerHtmlHtml content between opening and closing of the tags,used for formatting,, InnertextThe text content between the opening and closing of the tags
HtmlInputControl class PropertyDescription TypeProvides the type of input control ValueReturns the content of the control as string
Page class Every web page is a custom class that inherits from the Page class
Page Class Property Fundamental PropertyDescription Application & SessionIt holds the information about the state CacheStores Objects for reuse ControlsProvides a collection of the web controls in that Page EnableViewState
Page Class Properties Fundamental PropertyDescription IsPostBackBoolean Property checks whether the Page is submitted for the first time RequestRefer to the HttpRequest object that holds the information about the current web request ResponseSet the web response or redirect the user to other web page
Page Class Properties Fundamental PropertyDescription ServerRefers to the HttpServer utility performs some tasks like URL,Html encoding UserIf the user has been authenticated then this property will be initialized with the user information
HttpRequest class The HttpRequest class encapsulates all the information related to the client request for a web page
HttpRequest class PropertyDescription ApplicationPathGets the virtual directory (URL) PhysicalPathGets the real directory (URL) BrowserProvides link to the HttpBrowserCapabilities object which contains the browser features ClientCertificateGets the security certificate if there exists one
HttpRequest class PropertyDescription CookiesGets the collection cookies sent with the request Headers\ Servervariables Provides a name\value collection of HTTP headers and server variables IsAuthenticated IsSecureConnection Returns true if user is authenticated and secure sockets are used
HttpRequest class PropertyDescription QueryStringProvides the parameters that were passed along with query string Url and UrlReferrer Current address of the page and the address of the page from where the user has navigated from UserAgentA string representing the browser type.IE provides the value “MSIE”
HttpRequest class PropertyDescription UserLanguagesProvides a sorted string array that lists the clients language
Server Variables Request Method Server Name Server Port Server Protocol Server Software
The HttpResponse Class This class allows you to send information directly to the client Some of the important functionalities Caching Support Cookie features Redirect method
PropertyDescription BufferOutputDefault set to (true) the page is not sent to the client CacheRefers to the HttpCache policy CookiesThe collection of cookies sent with response Write(), BinaryWrite() WriteFile() Allows you to write text or binary content directly to the response stream
PropertyDescription Redirect()Transfers the user to another page or another website
The Server Utility Class The ServerUtility class provides some miscellaneous helper methods
PropertyDescription CreateObjectCreates an instance of the COM object that is identified by its ID HtmlEncode, HtmlDecode Changes an ordinary string into a string with legal HTML characters UrlEncode, UrlDecode Changes an ordinary string into a string with legal URL characters
PropertyDescription MapPathReturns the Physical path TransferSimilar to response.redirect method