Most Asked ASP.NET Property, Methods And Events In Interview

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.

  1. @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 %>

  2. @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 %>

  3. @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 %>

  4. 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()

  5. 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
    );


  6. 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


  7. 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";
    }


  8. 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>


  9. 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>


  10. 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" />

  11. 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()

  12. 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()

  13. 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.

  14. 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)

  15. 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)

  16. 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;

  17. 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";

  18. 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()

  19. 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;

  20. 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();


  21. 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])

  22. 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]

  23. 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);

  24. 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" />

  25. 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"/>


  26. 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"/>


  27. 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>


  28. 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)

  29. 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;

  30. 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);


  31. 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") %>

  32. 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();

  33. 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>")
    %>


  34. 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;

  35. 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;

  36. 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();

  37. 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]

  38. GET

    Namespace/Class: HttpRequest Class
    Type: Method
    Description: Requests data from a specified resource.

    Syntax
    :

    GetLastError()

  39. 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
    )


  40. 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]

  41. 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()

  42. 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
    %>


  43. 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)

  44. 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()

  45. 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");


  46. 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);
    %>


  47. Response.Redirect

    Namespace/Class:
    System.Web

    Type: Method
    Description: The Redirect method causes the browser to redirect the client to a different URL.

    Syntax
    :

    Request.QueryString (variable)[(index)|.Count]

  48. 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
    )


  49. 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>


  50. 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
    %>


Similar Articles