Web Forms with Asp.Net

– Web Applications Characteristics:

  • Multiuser
  • Designed to be executed on server and viewed in client
  • Most of web applications are stateless

– HTML controls are executed on client and Asp controls are executed on server

– In action attribute you specify the URI of the agent that handles the processing on the form

– With method attribute you specify that the form will use either the HTTP-POST or HTTP-GET to talk to server

  • When using HTTP-POST, the URI of the agent is called with the parameters specified in the form as name/value pairs in the URI. As a result, the call will look something like this: http://server/application?param=value&param=value
    • Usually HTTP-GET is used to request information from server (pull model)
    • If there had been parameters encoded in the query string (the URL), as is the case with HTTP-GET, we could access those values through the HttpRequest.QueryString parameter
  • When using HTTP-POST, values are embedded within the body of the HTTP request itself, following the HTTP header values
    • Usually HTTP-POST is used to send data to server (push model)
    • When using HTTP-POST: string value = Request.Form[“ItemName”];
    • You can add values to property HttpRequest

– Why ASP.net is stateless

Processing of events is done by the flow:

  • When the page first runs, ASP.NET prepares the HTML to send to the client then destroy it from server memory
  • User trigger postback to server
  • Then page is send to server and ASP.NET stores the state of each control
  • Executes the event handler of the triggered event
  • Modified page is rendered back into HTML and returned to the client

– Using Automatic Postback you can make a control response right away (like city list)

  • Here this is achieved by enabling the AutoPostBack property

Session State Concept:

  • Having permanent data available during browning period
  • Methods to support statefull application:
    • Cookies:
      • Disadvantages:
        • They lead to security problems and privacy issues
        • Requires a lot of development overhead
      • View State:
        • Solves most of Cookies problems
        • Disadvantage here is that the size of page is increased by the view state info

Note:

  • If an excessively large page is giving you a problem, you can override view state by setting the EnableViewState property to false. Thus, when designing your application, you can optimize it for page size by enabling view state only for the controls that you want to maintain state for

image

Page Framework Initialization:

  • Here ASP.Net initializes the page memory on the server
  • Then page fires Page .Init event here you can perform actions upon initializing the page but UI actions are not permitted because UI rendering has not occurred yet

Application Code Initialization:

  • Page_Load will fired at this point
  • This event most is used for initialization issues
  • You can use Page.IsPostBack to make a distinction between page initialization and reloading

Performing Event Handling:

  • If a number of lists are used with no AutoPostBack, and the user selects items on them before pressing a button on the page—then each of these events will have their handler called at this stage

Performing Data Binding:

  • Any data binding that updates the data store via an insert, a delete, or an update will occur after all the control events are handled, but before the Page_PreRender occur. Then, after the PreRender event, the functionality that queries the data store will fire. This ensures that data isn’t stale, because any functionality on your page that updates the data store will happen before anything is read from the data store. Therefore, the data on your page is always up-to-date

– Use Page.Controls to access all controls

– [Programming] Changing the page title dynamically using Title property

– [Programming] Adding controls in run time: Page.Form.Controls.Add

  • Here we are adding controls to control container

– Common page elements:

  • Request
  • Response
  • Used to redirect web pages: Response.Redirect(“url”)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s