We have lots of properties, directives, methods and event that is mostly used
by every ASP.NET programmer and are useful. So, let’s have a look on some most
important properties, methods and events and syntax them into your ASP.NET code.
- @ENABLESESSIONSTATE
Namespace: System.Web.Configuration
Type: Directive
Description: This is a directive which specifies whether a .aspx file uses session state or not. We can use this directive on the page level or application level.
Syntax:
<%@ ENABLESESSIONSTATE = False %>
- @LANGUAGE
Namespace/Class: Application Directive
Type: Directive
Description: @LANGUAGE processing directive is to set the language that is used to interpret the commands in a script. You can set your scripting language to any scripting engine that has been installed in IIS. The default scripting language is VBScript, so if you do not include the @LANGUAGE directive in your script, the script is interpreted by the VBScript engine.
Syntax:
<%@ LANGUAGE = Scriptengine %>
- @TRANSACTION
Namespace/Class: UserControl
Type: Directive
Description: You can use the @TRANSACTION processing directive to indicate that the script should be treated as a transaction. If a script is treated as a transaction, Component Services creates a transaction to coordinate the updating of resources.
Syntax:
<%@ TRANSACTION = value %>
- Session.Abandon
Namespace/Class: System.Web.SessionState
Type: Method
Description: This method is used to clear or destroy all the already stored object in session forcefully from server side. If we don’t call sessions abandon method the server clears session after time out. And by default timeout is 20 minutes.
Syntax:
Session.Abandon()
- Response.AddHeader
Namespace/Class: HttpResponse/System.Web
Type: Method
Description: The AddHeader method adds a new HTML header and value to the response sent to the client. It does not replace an existing header of the same name. After a header has been added, it cannot be removed.
Syntax:
public void AddHeader(
string name,
string value
);
- Response.AppendToLog
Namespace/Class: System.Web.UI.WebControls
Type: Method
Description: The AppendToLog method is used to add a string to the end of the Web server log entry for every request from the browser. We can use it multiple times in the same section of script. Every time when it calls, it appends the specified string to the existing entry in request.
Syntax:
[ValidationPropertyAttribute("SelectedItem")]
public class ListBox : ListControl, IPostBackDataHandler
- Application
Namespace/Class: System.Web
Type: Object
Description: We can use this Application object to share information for all users of a web application. Application object can be shared by more than one user with same information, there are Lock and Unlock methods in Application Class to ensure that multiple users do not try to change the value of this property simultaneously.
Syntax:
HttpContext.Current.Application OR void Application_Start(object sender, EventArgs e)
{
// Code that runs on application startup
Application["UserID"] = "SureshDasari";
}
- Application_OnEnd
Namespace/Class: System.Diagnostics
Type: Event
Description: Application_onEnd is an event that exists in Global.asax file in ASP.NET project and it occurs when the application ends after session_End event. It is only at once for all users.
Syntax:
<script language="vbscript" runat="server">Sub Application_OnEnd
. . .
End Sub
</script>
- Application_OnStart
Namespace/Class:System.Diagnostics
Type: Event
Description: Application_OnStartit is an event which also exists in Global.asax file in ASP.ENT project and it occurs when the application starts before session_start event. It is only at once for all users.
Syntax:
<script language="vbscript" runat="server">
Sub Application_OnStartEnd Sub</script>
- AlternateText
Namespace/Class: System.Web.UI.WebControls/ button control
Type: Property
Description: AlternateText is a property for image button control only. The text to be displayed if the browser cannot display the image.
Syntax:
<asp:Image AlternateText="String" />
- ASPCode
Namespace/Class: ASPError Object
Type: Property
Description: AspCode is a property from class ASPErrorObject, the property returns an error code generated by IIS.
Syntax:
ASPError.ASPCode()
- ASPDescription
Namespace/Class: System.Web.UI.WebControls
Type: Property
Description: It is just used for returning a detailed description of the error.
Syntax:
ASPError.ASPDescription()
- ASPError
Namespace/Class: Server.GetLastError
Type: Object
Description: ASPError is used in a script to display information about errors in scripts.
Syntax:
ASPError object has no methods.
- Request.BinaryRead
Namespace/Class: System.Diagnostics
Type: Method
Description: The BinaryRead method retrieves data sent to the server from the client as part of a POST request.
Syntax:
Request.BinaryRead(count)
- Response.BinaryWrite
Namespace/Class: Syatem.WEB
Type: Method
Description: It writes data directly to the output without any character conversion.
Syntax:
void BinaryWrite(Byte[] buffer)
- Response.Buffer
Namespace/Class: HttpResponse.Buffer
Type: Property
Description: When page output is buffered, the server does not send a response to the client until all the server scripts on the current page have been processed, or until the Flush or End method is called.
The Buffer property cannot be set after the server has sent output to the client. For this reason, the call to Response.Buffer should be the first line of the .asp file.
Syntax:
Response.Buffer = true;
- Response.CacheControl
Namespace/Class: HttpResponse.CacheControl
Type: Property
Description: Sets whether a proxy server can cache the output generated by ASP or not.
Syntax:
Response.CacheControl = "Public";
- ASPError.Category
Namespace/Class: Server.GetLastError
Type: Property
Description: The Category property is used to check the category of error and returns a string that is used to indicate whether the error was generated by IIS, a scripting language, or a component or source code.
Syntax:
ASPError.Category()
- Response.Charset
Namespace/Class: HttpResponse.Charset
Type: Property
Description: The Charset property appends the name of the character to the content-type header in the Response object.
Syntax:
string charSet = Response.Charset;
- Response.Clear
Namespace/Class: HttpResponse.Clear()
Type: Method
Description: The Clear method erases any buffered HTML output. However, the Clear method erases only the response body; it does not erase response headers.
Syntax:
Response.Clear();
- Request.ClientCertificate
Namespace/Class: System.Web
Type: Collection
Description: Request.ClientCertificate holds fields of keys and values from a security certificate that the client browser passes to the Web server.
Syntax:
Request.ClientCertificate(Key[SubField])
- Response.CodePage
Namespace/Class: System.Web.UI
Type: Property
Description: For the current response, the Response.CodePage property specifies, how strings are encoded in the intrinsic objects. Defines a code page (character set) for the system running the script engine.
Syntax:
Response.CodePage [=CodePageID]
- Connect
Namespace/Class: System.Data.OleDb
Type: Method
Description: It converts the request connection to a transparent TCP/IP tunnel.
Syntax:
dbconn=New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0);
- CausesValidation
Namespace/Class: System.Web.UI.WebControls
Type: Property
Description: The property is used to determine whether page validation occurs when a user clicks the button. The default is true.
Syntax:
<asp:CheckBoxCausesValidation="True|False" />
- CommandName
Namespace/Class: System.Web.UI.WebControls
Type: Property
Description: A string value that is passed to the command name to the event when a user clicks the button that is mostly used in DataBind Controls to get the command on button click in event bubbling.
Syntax:
<asp:Button id="Button1"
Text="Submit"
CommandName="Submit"
OnCommand="CommandBtn_Click"
runat="server"/>
- CommandArgument
Namespace/Class: System.Web.UI.WebControls
Type: Property
Description: A string value that is passed to the CommandArgument to the event when a user clicks the button that is mostly used in DataBind Controls to get the command on button click in event bubbling.
Syntax:
<asp:Button id="Button1"
Text="Sort Ascending"
CommandName="Sort"
CommandArgument="Ascending"
OnCommand="CommandBtn_Click"
runat="server"/>
- PostBackUrl
Namespace/Class: System.Web.UI.WebControls
Type: Property
Description: The URL of the page that is requested when the user clicks the button. It gets the request in POST state.
Syntax:
<asp:button id="Button1"
text="Post back to this page"
runat="Server">
</asp:button>
- Application.Contents
Namespace/Class: System.Web.UI.WebControls
Type: Collection
Description: You can use the Contents collection to obtain a list of items that have been given application scope or to specify a particular item to be the target of an operation.
Syntax:
Application.Contents( Key)
- Response.ContentType
Namespace/Class: HttpResponse.ContentType
Type: Property
Description: For a full list of content types, see your browser documentation or the HTTP specification.
Syntax:
string contentType = Resposen.ContentType;
- Request.Cookies
Namespace/Class: HttpResponse.Cookies
Type: Collection
Description: Request.Cookies is a collection for sharing the information in an ASP.NET web application among the web pages. Request.Cookies is also a part of state management of client side storage.
Syntax:
HttpCookienewCookie = new HttpCookie("FullName");
newCookie.Value = "TriConsole";
Response.Cookies.Add(newCookie);
- Server.CreateObject
Namespace/Class: HttpServerUtility Class
Type: Method
Description: The CreateObject method creates an instance of a server component. OnStartPage method is called at this time.
Syntax:
<% Set MyAd = Server.CreateObject("MSWC.AdRotator") %>
- Response.End
Namespace/Class: HttpResponse
Type: Method
Description: The End method causes the Web server to stop processing the script and return the current result. The remaining contents of the file are not processed.
Syntax:
Response.End();
- Server.Execute
Namespace/Class: HttpServerUtility.Execute
Type: Method
Description: Server.Execute is a method which is used to execute an ASP file inside another ASP file.
Syntax:
File1.asp:
<%
response.write("I am in File 1!<br>")
Server.Execute("file2.asp")
response.write("I am back in File 1!")
%>
File2.asp:
<%
response.write("I am in File 2!<br>")
%>
- Response.Expires
Namespace/Class: HttpResponse.Expires
Type: Property
Description: The Expires property is used to specify the duration of time before a page that is cached on a browser expire after the time duration. If the user returns to the same page before it expires, the cached version is displayed.
Syntax:
Response.Expires = 60;
- Response.ExpiresAbsolute
Namespace/Class: HttpResponse.ExpiresAbsolute
Type: Property
Description: The ExpiresAbsolute property is just used to specify the date and time at which a page cached on a browser expires.
Syntax:
Response.ExpiresAbsolute = DateTime.Now;
- Response.Flush
Namespace/Class: HttpResponse.Flush()
Type: Method
Description: The Flush method sends buffered output immediately. This method causes a run-time error if Response.Buffer has not been set to TRUE.
Syntax:
Response.Flush();
- Request.Form
Namespace/Class: FormCollection
Type: Collection
Description: The Form collection retrieves the values of form elements posted to the HTTP request body, with a form using the POSTmethod.
Syntax:
Request.Form(element)[(index)|.Count]
- GET
Namespace/Class: HttpRequest Class
Type: Method
Description: Requests data from a specified resource.
Syntax:
GetLastError()
- Server.HTMLEncode
Namespace/Class: HttpUtility.HtmlEncode
Type: Method
Description: The HTMLEncode method applies HTML encoding to a specified string. This is useful as a quick method of encoding form data and other client request data before using it in your Web application.
Syntax:
HTMLEncode(
string
)
- Response.LCID
Namespace/Class: System.Web
Type: Property
Description: The LCID property specifies how dates, times, and currencies are formatted. Locale identifiers (LCIDs) are not the same for each geographical locale.
Syntax:
Response.lcid [=LocaleID]
- ASPError.Line
Namespace/Class: System.Web
Type: Method
Description: It is used to ensure that only one client at a time can modify the Application variables
Syntax:
ASPError.Line()
- Application.Lock
Namespace/Class: System.Web
Type: Method
Description: The Lock method blocks other clients from modifying the variables stored in the Application object, ensuring that only one client at a time can alter or access the Application variables.
Syntax:
<%
Application.Lock
Application("visits")=Application("visits")+1
Application.Unlock
%>
- Server.MapPath
Namespace/Class: Server.GetLastError
Type: Property
Description: The MapPath method maps the specified relative or virtual path to the corresponding physical directory on the server. It returns a string value of physical path from server.
Syntax:
Server.MapPath(path)
- ASPError.Number
Namespace/Class: Server.GetLastError
Type: Method
Description: The Number property returns a long integer that contains the error code returned by a COM component. This is a standard COM error code.
Syntax:
ASPError.Number()
- ObjectContext
Namespace/Class: System.Data.Objects
Typeobject:
Description: You can use the ObjectContext object to either commit or abort a transaction, managed by Component Services, that has been initiated by a script contained in an ASP page.
Syntax:
ObjectContext context =
newObjectContext("name=AdventureWorksEntities");
- Request.QueryString
Namespace/Class: System.Web
Type: Collection
Description: The QueryString collection retrieves the values of the variables in the HTTP query string. The HTTP query string is specified by the values following the question mark (?).
Syntax:
<%
string URL = "http://www.example.com/rendernews.php?"+Request.Querystring;
System.Net.WebClientwc = new System.Net.WebClient();
string data = wc.DownloadString(URL);
Response.Output.Write(data);
%>
- Response.Redirect
Namespace/Class:
Type: Method
Description: The Redirect method causes the browser to redirect the client to a different URL.
Syntax:
Request.QueryString (variable)[(index)|.Count]
- OnStartPage
Namespace/Class: System.Drawing.Printing
Type: Event
Description: For all objects attached to that page, session, or application. This call occurs one time.
Syntax:
public override void OnStartPage(
PdfWriter writer,
Document document
)
- OnTransactionAbort
Namespace/Class: System.Transactions
Type: Event
Description: Event-handling subroutine raised when the transaction is aborted within the page
Syntax:
<script runat="server">
[DirectMethod]
public void AbortTransaction(int width, int height)
{
}
</script>
- OnTransactionCommit
Namespace/Class: System.Transactions
Type: Event
Description: Event-handling subroutine raised when the transaction completes within the page
Syntax:
<%@ TRANSACTION=Required LANGUAGE=ScriptLanguage%>
<%
Sub OnTransactionAbort
...Script...
End Sub
%>