Home
ASP.Net
Interview FAQs

We can write formatted output  using Response.Output.Write().

The appSettings block in web config file sets the user-defined values for the whole application.
For example, in the following code snippet, the specified ConnectionString section is used throughout the project for database connection:

<configuration>
<appSettings>
<add key=”ConnectionString” value=”server=local; pwd=password; database=default” />
</appSettings>
</configuration>


A breakpoint is a marker in your source code that triggers automatic entry into break mode.
These features are available only in debug builds. If you compile a release build, all breakpoints are ignored. There are several ways to add breakpoints. To add simple breakpoints that break when a line is reached, just left-click on the far left of the line of code, right-click on the line, and select Breakpoint ? Insert Breakpoint; select Debug ? Toggle Breakpoint from the menu; or press F9.
A breakpoint appears as a red circle next to the line of code

Error is just an event, it occur when something wrong happened. When error event occurs, CLR creates an object of type Exception (located in System namespace. 

Note:Error is an event and exception is .Net object. 

Master pages provide functionality that developers have traditionally created by copying existing code, text, and control elements repeatedly; using framesets; using include files for common elements; using ASP.NET user controls; and so on. Advantages of master pages include the following:

  • They allow you to centralize the common functionality of your pages so that you can make updates in just one place.
  • They make it easy to create one set of controls and code and apply the results to a set of pages. For example, you can use controls on the master page to create a menu that applies to all pages.
  • They give you fine-grained control over the layout of the final page by allowing you to control how the placeholder controls are rendered.
  • They provide an object model that allows you to customize the master page from individual content pages.

Two options for tracking session IDs-

  • By default, ASP.NET uses cookie-based session tracking to keep track of user sessions. However, if a browser doesn?t support cookies, this does not work.
  • With cookieless session tracking, the session ID is encoded as part of the URL. As a result, cookieless session state works whether or not the browser supports cookies.

A method that creates a new cookie and adds it to the HttpResponse object

private void AddCookie()
{
HttpCookie nameCookie = new HttpCookie("UserName",txtUserName.Text)
nameCookie.Expires = DateTime.Now.AddYears(1);
Response.Cookies.Add(nameCookie);
}

A method that retrieves the value of a cookie from the HttpRequest object
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (!(Request.Cookies["UserName"] == null))
lblUserName.Text = "Welcome back " + Request.Cookies["UserName"].value;
}
}

A method that deletes a persistent cookie

private void DeleteCookie()
{
HttpCookie nameCookie = new HttpCookie("UserName");
nameCookie.Expires = DateTime.Now.AddSeconds(-1);
Response.Cookies.Add(nameCookie);
}

A hyperlink with a URL that includes a query string
<asp:HyperLink ID="HyperLinkl" runat="server" NavigateUrl="~/w3asp.aspx?cat=fx&prod=fogOl">Pog machine
</asp:HyperLink>

An anchor element with a URL that includes a query string
<a href="w3asp.aspx?cat=fx&prod=fog01">Fog machine</a>
Statements that retrieve the values of the query string attributes
string categorylD = Request.QueryString["cat"];
string productID = Request.QueryString["prod"];

Code that uses a URL with a query string in a Redirect method
Response.Redirect("w3asp.aspx?cat=" + categorylD);

The web.config file has a connectionStrings element that contains an add element for each connection string. In the example, the connection string is named w3aspConnectionString,and the connection string refers to a database named Halloween on the server named localhost\sqlexpress.The ConnectionStrings section of the web.config file-

<connectionStrings>

<add name="w3aspConnectionString" connectionString="DataSource=localhost\sqlexpress; Initial Catalog=w3asp;Integrated Security=True"

providerName="System.Data.SqlClient"/>

</connectionStrings>

PreviousDisplaying 41 of 46Next
Need Help? Contact Us.

Log in

*
*

Forgot password?

*

New User

*
*
*
*