Page 5 - ASP.NET 2.0 Interview Questions
 

Q11. Is Visual Web Developer XHTML compliant?

A11. Yes.

Q12. What are server controls?

A12. ASP.NET pages can contain server controls, which are programmable server-side objects that typically represent a UI element in the page, such as a textbox or image. Server controls participate in the execution of the page and produce their own markup rendering to the client. The principle advantage of server controls is that they enable developers to get complex rendering and behaviors from simple building-block components, dramatically reducing the amount of code it takes to produce a dynamic Web page. Another advantage of server controls is that it is easy to customize their rendering or behavior. Server controls expose properties that can be set either declaratively (on the tag) or programmatically (in code). Server controls (and the page itself) also expose events that developers can handle to perform specific actions during the page execution or in response to a client-side action that posts the page back to the server (a "postback"). Server controls also simplify the problem of retaining state across round-trips to the server, automatically retaining their values across successive postbacks.

Server controls are declared within an .aspx file using custom tags or intrinsic HTML tags that contain a runat="server" attribute value. Intrinsic HTML tags are handled by one of the controls in the System.Web.UI.HtmlControls namespace. Any tag that doesn't explicitly map to one of the controls is assigned the type of System.Web.UI.HtmlControls.HtmlGenericControl.

Q13. How do server control handle events?

A13. ASP.NET server controls can optionally expose and raise server events, which can be handled by page developers. A page developer may accomplish this by declaratively wiring an event to a control (where the attribute name of an event wireup indicates the event name and the attribute value indicates the name of a method to call).

Sub EnterBtn_Click(Sender As Object, E As EventArgs)
            Message.Text = "Hi " & Name.Text & ", wazzup there!"
End Sub


Q14. How to Navigate to another page?

A14. The following sample demonstrates how to use the <asp:hyperlink runat=server> control to navigate to another page (passing custom query string parameters along the way). The sample then demonstrates how to easily get access to these query string parameters from the target page.

<asp:hyperlink id="hl_Link" runat=server text="click here" NavigateUrl="www.somelink.com">
</asp:hyperlink>

This navigation triggers when a click is made on the hyperlink. If we want navigation to trigger through code, we may use response.redirect(URL) or server.transfer(URL)

Q15. What is Simplified Code Behind Model in ASP.NET 2.0?

A15. ASP.NET 2.0 introduces an improved runtime for code-behind pages that simplifies the connections between the page and code. In this new code-behind model, the page is declared as a partial class, which enables both the page and code files to be compiled into a single class at runtime. The page code refers to the code-behind file in the CodeFile attribute of the <%@ Page %> directive, specifying the class name in the Inherits attribute. Note that members of the code behind class must be either public or protected (they cannot be private).

Example

Codebehind

Partial Class CodeBehind_vb_aspx
Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Label1.Text = "Hello " & TextBox1.Text
    End Sub
End Class

Inline Code

<%@ page language="VB" CodeFile="CodeBehind_vb.aspx.vb" Inherits="CodeBehind_vb_aspx" %>

<html>
<head>
    <title>ASP.NET CodeBehind Pages</title>
</head>
<body>
    <form runat="server">
      <h1>Welcome to ASP.NET 2.0!</h1>
      <b>Enter Your Name:</b>
      <asp:TextBox ID="TextBox1" Runat="server"/>
      <asp:Button ID="Button1" Text="Click Me" OnClick="Button1_Click" Runat="server"/>
      <br />
      <br />
      <asp:Label ID="Label1" Text="Hello" Runat="server" />
    </form>
</body>
</html>


Q16. Whats the advantage of Simplified Code Behind model?

A16. The advantage of the simplified code-behind model over previous versions is that you do not need to maintain separate declarations of server control variables in the code-behind class. Using partial classes (new in 2.0) allows the server control IDs of the ASPX page to be accessed directly in the code-behind file. This greatly simplifies the maintenance of code-behind pages.

 

Home Prev Next