Notice: A non well formed numeric value encountered in C:\ClientSites\reviewhostingasp.net\httpdocs\wp-content\plugins\crayon-syntax-highlighter\crayon_formatter.class.php on line 118
Notice: A non well formed numeric value encountered in C:\ClientSites\reviewhostingasp.net\httpdocs\wp-content\plugins\crayon-syntax-highlighter\crayon_formatter.class.php on line 119
Notice: A non well formed numeric value encountered in C:\ClientSites\reviewhostingasp.net\httpdocs\wp-content\plugins\crayon-syntax-highlighter\crayon_formatter.class.php on line 118
Notice: A non well formed numeric value encountered in C:\ClientSites\reviewhostingasp.net\httpdocs\wp-content\plugins\crayon-syntax-highlighter\crayon_formatter.class.php on line 119
ASP.NET client side coding has two aspects:
- Client side scripts : It runs on the browser and in turn speeds up the execution of page. For example, client side data validation which can catch invalid data and warn the user accordingly without making a round trip to the server.
- Client side source code : ASP.NET pages generate this. For example, the HTML source code of an ASP.NET page contains a number of hidden fields and automatically injected blocks of JavaScript code, which keeps information like view state or does other jobs to make the page work.
Client Side Scripts
All ASP.NET server controls allow calling client side code written using JavaScript or VBScript. Some ASP.NET server controls use client side scripting to provide response to the users without posting back to the server. For example, the validation controls.
Apart from these scripts, the Button control has a property OnClientClick, which allows executing client-side script, when the button is clicked.
The traditional and server HTML controls have the following events that can execute a script when they are raised:
Event | Description |
---|---|
onblur | When the control loses focus |
onfocus | When the control receives focus |
onclick | When the control is clicked |
onchange | When the value of the control changes |
onkeydown | When the user presses a key |
onkeypress | When the user presses an alphanumeric key |
onkeyup | When the user releases a key |
onmouseover | When the user moves the mouse pointer over the control |
onserverclick | It raises the ServerClick event of the control, when the control is clicked |
Client Side Source Code
We have already discussed that, ASP.NET pages are generally written in two files:
- The content file or the markup file ( .aspx)
- The code-behind file
The content file contains the HTML or ASP.NET control tags and literals to form the structure of the page. The code behind file contains the class definition. At run-time, the content file is parsed and transformed into a page class.
This class, along with the class definition in the code file, and system generated code, together make the executable code (assembly) that processes all posted data, generates response, and sends it back to the client.
Consider the simple page:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | <span class="pun"><%@</span> <span class="typ">Page</span> <span class="typ">Language</span><span class="pun">=</span><span class="str">"C#"</span> <span class="typ">AutoEventWireup</span><span class="pun">=</span><span class="str">"true"</span> <span class="typ">CodeBehind</span><span class="pun">=</span><span class="str">"Default.aspx.cs"</span> <span class="typ">Inherits</span><span class="pun">=</span><span class="str">"clientside._Default"</span><span class="pln"> %> </span><span class="dec"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></span> <span class="tag"><html</span> <span class="atn">xmlns</span><span class="pun">=</span><span class="atv">"http://www.w3.org/1999/xhtml"</span> <span class="tag">></span> <span class="tag"><head</span> <span class="atn">runat</span><span class="pun">=</span><span class="atv">"server"</span><span class="tag">></span> <span class="tag"><title></span><span class="pln"> Untitled Page </span><span class="tag"></title></span> <span class="tag"></head></span> <span class="tag"><body></span> <span class="tag"><form</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"form1"</span> <span class="atn">runat</span><span class="pun">=</span><span class="atv">"server"</span><span class="tag">></span> <span class="tag"><div></span> <span class="tag"><asp:TextBox</span> <span class="atn">ID</span><span class="pun">=</span><span class="atv">"TextBox1"</span> <span class="atn">runat</span><span class="pun">=</span><span class="atv">"server"</span><span class="tag">></asp:TextBox></span> <span class="tag"><asp:Button</span> <span class="atn">ID</span><span class="pun">=</span><span class="atv">"Button1"</span> <span class="atn">runat</span><span class="pun">=</span><span class="atv">"server"</span> <span class="atn">OnClick</span><span class="pun">=</span><span class="atv">"</span><span class="typ">Button1_Click</span><span class="atv">"</span> <span class="atn">Text</span><span class="pun">=</span><span class="atv">"Click"</span> <span class="tag">/></span> <span class="tag"></div></span> <span class="tag"><hr</span> <span class="tag">/></span> <span class="tag"><h3></span> <span class="tag"><asp:Label</span> <span class="atn">ID</span><span class="pun">=</span><span class="atv">"Msg"</span> <span class="atn">runat</span><span class="pun">=</span><span class="atv">"server"</span> <span class="atn">Text</span><span class="pun">=</span><span class="atv">""</span><span class="tag">></span> <span class="tag"></asp:Label></span> <span class="tag"></h3></span> <span class="tag"></form></span> <span class="tag"></body></span> <span class="tag"></html></span> |
When this page is run on the browser, the View Source option shows the HTML page sent to the browser by the ASP.Net runtime:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | <span class="dec"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></span> <span class="tag"><html</span> <span class="atn">xmlns</span><span class="pun">=</span><span class="atv">"http://www.w3.org/1999/xhtml"</span> <span class="tag">></span> <span class="tag"><head></span> <span class="tag"><title></span><span class="pln"> Untitled Page </span><span class="tag"></title></span> <span class="tag"></head></span> <span class="tag"><body></span> <span class="tag"><form</span> <span class="atn">name</span><span class="pun">=</span><span class="atv">"form1"</span> <span class="atn">method</span><span class="pun">=</span><span class="atv">"post"</span> <span class="atn">action</span><span class="pun">=</span><span class="atv">"Default.aspx"</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"form1"</span><span class="tag">></span> <span class="tag"><div></span> <span class="tag"><input</span> <span class="atn">type</span><span class="pun">=</span><span class="atv">"hidden"</span> <span class="atn">name</span><span class="pun">=</span><span class="atv">"__VIEWSTATE"</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"__VIEWSTATE"</span> <span class="atn">value</span><span class="pun">=</span><span class="atv">"/wEPDwUKMTU5MTA2ODYwOWRk31NudGDgvhhA7joJum9Qn5RxU2M="</span> <span class="tag">/></span> <span class="tag"></div></span> <span class="tag"><div></span> <span class="tag"><input</span> <span class="atn">type</span><span class="pun">=</span><span class="atv">"hidden"</span> <span class="atn">name</span><span class="pun">=</span><span class="atv">"__EVENTVALIDATION"</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"__EVENTVALIDATION"</span> <span class="atn">value</span><span class="pun">=</span><span class="atv">"/wEWAwKpjZj0DALs0bLrBgKM54rGBhHsyM61rraxE+KnBTCS8cd1QDJ/"</span><span class="tag">/></span> <span class="tag"></div></span> <span class="tag"><div></span> <span class="tag"><input</span> <span class="atn">name</span><span class="pun">=</span><span class="atv">"TextBox1"</span> <span class="atn">type</span><span class="pun">=</span><span class="atv">"text"</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"TextBox1"</span> <span class="tag">/></span> <span class="tag"><input</span> <span class="atn">type</span><span class="pun">=</span><span class="atv">"submit"</span> <span class="atn">name</span><span class="pun">=</span><span class="atv">"Button1"</span> <span class="atn">value</span><span class="pun">=</span><span class="atv">"Click"</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"Button1"</span> <span class="tag">/></span> <span class="tag"></div></span> <span class="tag"><hr</span> <span class="tag">/></span> <span class="tag"><h3><span</span> <span class="atn">id</span><span class="pun">=</span><span class="atv">"Msg"</span><span class="tag">></span></h3></span> <span class="tag"></form></span> <span class="tag"></body></span> <span class="tag"></html></span> |
If you go through the code properly, you can see that first two <div> tags contain the hidden fields which store the view state and validation information.