Interview Questions & Answer on ASP.NET Controls

Q : What are the 2 types of controls that you can use on a webform in ASP.NET?

Ans : Web Server Controls
HTML Controls

Q : What’s the difference between Server controls and HTML controls?

Ans : 1. Server controls can trigger control-specific events on the server.HTML controls can trigger only page- level events on server (postback).

2. Data entered in a server control is maintained across requests. Server controls retain state.Data is not maintained in an HTML control. Data must be saved and restored using page-level scripts.

3. The Microsoft .NET Framework provides a set of properties for each server control. Properties allow you to change the server control’s appearance and behavior within server-side code.HTML controls have HTML attributes only.

4. Server controls automatically detect browser and adapt display as appropriate.HTML controls do not adapt automatically. You must detect browser in code or write for least common denominator.

Q : What are the 2 Layouts supported by a Web form in ASP.NET?

Ans : Grid layout - Controls are placed exactly where you draw them, and they have absolute positions on the page. Use grid layout for Microsoft Windows–style applications, in which controls are not mixed with large amounts of text. Pages using grid layout will not always display correctly in non-Microsoft browsers.

Flow layout - This layout positions controls relative to other elements on the page. If you add elements at run time, the controls that appear after the new element move down. Use flow layout for document-style applications, in which text and controls are intermingled.

Q : When do you choose between GridLayout and Flow layout for Web forms?

Ans : You use GridLayout for Web forms that have a fixed appearance. You use FlowLayout for Web forms that incorporate text and controls.When you create controls with GridLayout, Visual Studio adds style attributes to each control that set the position of the control.When you create controls with FlowLayout, Visual Studio omits the style attribute.

Q : Give 3 reasons why we use HTML controls over Server Controls?

Ans : Migration from earlier versions of Active Server Pages (ASP) : You can load an ASP application into Visual Studio and revise it gradually, rather than rewrite it completely. Earlier versions of ASP supported only HTML elements, and these elements become HTML controls when you load the project in Visual Studio .NET.

Not all controls require server-side events or state management : This is particularly true when you’re doing data binding. Bound items are usually refreshed from the data source with each request, so it’s more efficient not to maintain state information for bound controls. This means that you can use HTML controls or turn off state management for bound server controls.

You have complete control over what is rendered with HTML controls : ASP.NET adjusts the appearance of server controls based on the browser making the request. HTML controls are not adjusted, so you have direct control over their appearance.

Q : How can you prevent users from editing Text in TextBox control on a web form?

Ans : By making the TextBox a readonly TextBox. To make a TextBox readonly set the ReadOnly property to True.

Q : How do you convert an ASP.NET TextBox to accept passwords?

Ans : To convert and ASP.NET TextBox to accept passwords set the TextMode property to "Password"

Q : What happens when you set the AutoPostBack property of a TextBox to true?

Ans : When AutoPostBack property is set to True, the TextBox control fires a TextChanged postback event when the user leaves the TextBox control after changing the contents. By default, this property is set to False and the Text­Changed event is cached until some other postback event occurs.

Q : What are the 3 values that a TextMode property of TextBox can have?

Ans : SingleLine : Single Line TextBox
MultiLine : Multi Line TextBox(scrollable)
Password : When set to Password, the text box displays dots in place of the characters typed.

Q : How do you limit the number of characters entered by a user in the ASP.NET TextBox?

Ans : By setting the MaxLength property of the TextBox. If you set the MaxLength property to 10, a user can enter only 10 characters into the TextBox.


  « Previous    | Next »
Leave a Reply
Name (required)
Email (will not be published) (required)
Web Site

List of Top Hospitals in India