Interview Tips Interview Tips, Interview Questions and Answers

2Mar/110

ASP.NET – HTML Server Controls

HTML server controls are HTML tags understood by the server.

HTML elements in ASP.NET files are, by default, treated as text. To make these elements programmable, add a runat="server" attribute to the HTML element. This attribute indicates that the element should be treated as a server control. The id attribute is added to identify the server control. The id reference can be used to manipulate the server control at run time.

Note: All HTML server controls must be within a <form> tag with the runat="server" attribute. The runat="server" attribute indicates that the form should be processed on the server. It also indicates that the enclosed controls can be accessed by server scripts.

In the following example we declare an HtmlAnchor server control in an .aspx file. Then we manipulate the HRef attribute of the HtmlAnchor control in an event handler (an event handler is a subroutine that executes code for a given event). The Page_Load event is one of many events that ASP.NET understands:

<script runat="server">
Sub Page_Load
link1.HRef="http://www.jack-fx.com"
End Sub
</script>

<html>
<body>

<form runat="server">
<a id="link1" runat="server">Hello world</a>
</form>

</body>
</html>

The executable code itself has been moved outside the HTML.

17Oct/100

More Control Over Auto-Generated IDs in asp.net

In ASP.NET pages, using the same ID for two server controls isn't allowed. If this happens, the page won't compile -- period. In HTML, though, it is possible for two or more elements to share the same ID. In this case, when you make a search for an element via document.getElementById, you'll simply get an array of DOM elements. What about nested ASP.NET controls?

Most data-bound, template-based controls generate their output by repeating an HTML template for every data-bound item. This means that any child control defined with a unique ID in the template is being repeated multiple times. The original ID can't just be unique. For this reason, since the beginning, the ASP.NET team defined an algorithm to ensure that every HTML element emitted by an ASP.NET control could be given a unique ID. The ID resulted from the concatenation of the control ID with the ID of the naming container. Furthermore, in case of repeated controls (i.e., templates), a numeric index was added for disambiguation. For years, nobody really cared about the readability of the auto-generated ID, and strings like the following became fairly common:

ctl00$ContentPlaceHolder1$GridView11$TextBox1

14Oct/100

Simple Spark Expressions

At its core, Spark is a template engine that allows developer to quickly and cleanly express their intent inside of views. Two of the most common scenarios in view development are if/else conditionals and looping.

Spark provides a very easy-to-learn syntax for conditional statements. The syntax is so-self describing that HTML fluent designers can identify the intent while modifying HTML. In the following example, a Product is tested to see how much it is and the result will change upon the price of the product.

This is expensive.


This is not too bad.


This is a DEAL!

The snippet above illustrates that the if element construct is readable within the HTML, and the intent is easily discernible. There is no need to explain what is happening since the code is seamless with the surrounding HTML.

A similar syntax exists for conditional evaluation as well. The test element construct has the exact same functionality as the if element construct but with different syntax. The following is identical in functionality to the example above.

This is expensive.

This is not too bad.

This is a DEAL!

Note the enclosing test element and self-closing else elements.

A third and final method of conditional evaluation exists as an inline attribute. The functionality below renders the same output as above, but with inline if and elseif attributes.

This is expensive

This is not
too bad.

This is a DEAL!

Looping within Spark can take on many forms; however, the most commonly used method is to use the each attribute that can be decorated on any HTML element. The each attribute is used verbatim as shown below (so it must have the type, variable name, the “in” keyword and the collection).

class="alt?{productIndex % 2 == 0}">

Name: ${product.Name}

Price: ${product.Price}

31May/100

.NET WebDev interview questions

9. How will you identify which event in the ASP.NET Web page life cycle takes the longest time to execute?
A. Turn on ASP.NET trace and run the Web application.
B. Add a few code to each of the page life-cycle events that will print the current time.
C. In the Web.config file, add the monitorTimings attribute and set it to True.
D. In the Web site properties, turn on the performance monitor and run the Web application. After that, open performance monitor to see the timings.
11. You are interested in examining the data that is posted to the Web server. What trace result section can you use to see this information?
A. Control Tree
B. Headers Collection
C. Form Collection
D. Server Variables
12. While creating web site you need to add an HTML Web server control to the Web page, you need to drag an HTML element from the ToolBox of Visual Studio 2005 to the Web page and then which of the following tasks you will perform?
A. Right-click the HTML element and click Run=Server.
B. Double-click the HTML element to convert it to an HTML server control.
C. Right-click the HTML element and click Run As Server Control.
D. Click the HTML element and set ServerControl to true in the Properties window.
13. While testing your ASP.NET web application you noticed that while clicking on CheckBox of one of the web page it does not cause a PostBack; you required that the CheckBox should make PostBack so Web page can be update on the server-side code. How can you make the CheckBox to cause a PostBack?
A. Set the AutoPostBack property to true.
B. Add JavaScript code to call the ForcePostBack method.
C. Set the PostBackAll property of the Web page to true.
D. Add server-side code to listen for the click event from the client.
14. While writing code in Visual Studio 2005 you creates a new instance of a ASP.NET TextBox server control, what do you need to do to get the TextBox to display on the Web page?
A. Call the ShowControl method on the TextBox.
B. Set the VisibleControl to true on the TextBox.
C. Add the TextBox instance to the form1.Controls collection.
D. Execute the AddControl method on the Web page.
15. While creating your ASP.NET web based application you want to create multiple RadioButton server controls which should be mutually exclusive, what property of RadioButton server controls you must set?
A. Exclusive
B. MutuallyExclusive
C. Grouped
D. GroupName
16. While creating an ASP.NET web application with the help of Visual Studio 2005 you are creates a Web page that has several related buttons, such as fast-forward, reverse, play, stop, and pause. There should be one event handler that handles the processes of PostBack from these Button server controls. Other than the normal Submit button, what type of button can you create?
A. OneToMany
B. Command
C. Reset
D. ManyToOne

9. How will you identify which event in the ASP.NET Web page life cycle takes the longest time to execute? A. Turn on ASP.NET trace and run the Web application. B. Add a few code to each of the page life-cycle events that will print the current time. C. In the Web.config file, add the monitorTimings attribute and set it to True. D. In the Web site properties, turn on the performance monitor and run the Web application. After that, open performance monitor to see the timings.
11. You are interested in examining the data that is posted to the Web server. What trace result section can you use to see this information?A. Control Tree B. Headers Collection C. Form Collection D. Server Variables
12. While creating web site you need to add an HTML Web server control to the Web page, you need to drag an HTML element from the ToolBox of Visual Studio 2005 to the Web page and then which of the following tasks you will perform? A. Right-click the HTML element and click Run=Server. B. Double-click the HTML element to convert it to an HTML server control. C. Right-click the HTML element and click Run As Server Control. D. Click the HTML element and set ServerControl to true in the Properties window.
13. While testing your ASP.NET web application you noticed that while clicking on CheckBox of one of the web page it does not cause a PostBack; you required that the CheckBox should make PostBack so Web page can be update on the server-side code. How can you make the CheckBox to cause a PostBack? A. Set the AutoPostBack property to true. B. Add JavaScript code to call the ForcePostBack method. C. Set the PostBackAll property of the Web page to true. D. Add server-side code to listen for the click event from the client.
14. While writing code in Visual Studio 2005 you creates a new instance of a ASP.NET TextBox server control, what do you need to do to get the TextBox to display on the Web page? A. Call the ShowControl method on the TextBox. B. Set the VisibleControl to true on the TextBox. C. Add the TextBox instance to the form1.Controls collection. D. Execute the AddControl method on the Web page.
15. While creating your ASP.NET web based application you want to create multiple RadioButton server controls which should be mutually exclusive, what property of RadioButton server controls you must set? A. Exclusive B. MutuallyExclusive C. Grouped D. GroupName
16. While creating an ASP.NET web application with the help of Visual Studio 2005 you are creates a Web page that has several related buttons, such as fast-forward, reverse, play, stop, and pause. There should be one event handler that handles the processes of PostBack from these Button server controls. Other than the normal Submit button, what type of button can you create? A. OneToMany B. Command C. Reset D. ManyToOne