There are two aspects to client-side coding for ASP.NET:
Client-side script : It runs in the browser and in turn speeds up the execution of the page. For example, client-side data validation can catch invalid data and alert the user accordingly without posting back in the server.
Client Source Code : The ASP.NET web page forms this client source code. For example, the HTML source code of an ASP.NET web page contains several hidden areas and can automatically inject Java description language code to preserve information like view state or perform other tasks to ensure that the web page functions properly.
All ASP.NET server controls allow responsive coding via Java language or VBS language drawing. Some ASP.NET server controls use client-side scripts to respond to user needs without posting back to the server. For example, data validation controls.
In addition to these scripts, the button control has a proper OnClientClick method that executes client script when the button is clicked.
Traditional server HTML controls have the following events that can execute scripts when scripts are initiated:
event | property |
---|---|
onblur | Triggered when the control loses focus |
onfocus | Triggered when the control gains focus |
onclick | Fires when the control is clicked |
onchange | Triggered when the control value changes |
onkeydown | Fires when the user presses a keyboard button |
onkeypress | When the user presses an alphanumeric key |
onkeyup | Fires when the user releases the key |
onmouseover | Triggered when the user moves the mouse pointer on the control interface |
onserverclick | When the control interface is clicked, start the ServerClick event control |
We have discussed the client source code above. ASP.NET web pages are usually written in two types of files:
Content file or approval file (.aspx)
Code-behind files
Content files contain HTML or ASP.NET control tags and text to form the structure of the page. The code-behind file contains the classification definitions. At runtime, the content file is parsed and delivered to a page class.
This page class, along with the class definitions in the encoding file and the system-generated encoding, together constitute the execution encoding (integration). These integration encodings process all postback data, generate responses and send back actions to the client.
Consider this simple page:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="clientside._Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title> Untitled Page </title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Click" /> </div> <hr /> <h3> <asp:Label ID="Msg" runat="server" Text=""> </asp:Label> </h3> </form> </body></html>
When this page is run in a browser, the View Source option displays the HTML page and sends it to the browser via the ASP.Net runtime:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" > <head> <title> Untitled Page </title> </head> <body> <form name="form1" method="post" action="Default.aspx" id="form1"> <div> <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="/wEPDwUKMTU5MTA2ODYwOWRk31NudGDgvhhA7joJum9Qn5RxU2M=" /> </div> <div> <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="/wEWAwKpjZj0DALs0bLrBgKM54rGBhHsyM61rraxE+KnBTCS8cd1QDJ/"/> </div> <div> <input name="TextBox1" type="text" id="TextBox1" /> <input type="submit" name="Button1" value="Click" id="Button1" /> </div> <hr /> <h3><span id="Msg"></span></h3> </form> </body></html>
If you look through the coding properly, you'll see that the first two <div> tags contain hidden fields for storing view state and valid data.