ASP.NET Interview Questions and Answers (1544) - Page 29

How you can invoke programmatically all validation controls on a page?

You can invoke validation controls programmatically with the help of CallPage.Validate() method. These properties invoke the validation logic for each validation control in the defined validation group. When this method is invoked, it does through the validation controls associated with the Page.
What’s the difference between System.String and System.Text.StringBuilder classes?

System.String is immutable.

System.StringBuilder was designed with the purpose of having a mutable string where a variety of operations can be performed.
Can you programmatically store and retrieve data from ViewState?

Yes, you can programmatically store and retrieve data from ViewState in an ASP.NET application.

Example: To save the value in ViewState object
 ViewState("Name") = txtName.text;

Retrieve the value from ViewState object
String strName = ViewState("Name").ToString();

Is the ViewState of one page available to another page?

No, the ViewState of a Page is available only in that page. You cannot access ViewState of one page to another page.
Can the HTML controls retain State across postbacks? If no, can you make HTML controls retain State across postbacks?

No, by default the HTML controls doesn't retain any state across postbacks. But yes, if you are converting HTML controls to Server Controls then you can retain HTML control State across postbacks.

There are 2 ways to convert HTML control to Server Control.
• Right click on the HTML Control and then click "Run As Server Control"
• Set runat="server" attribute for the Control.
When a ViewState restoration happens and is it encoded?

The ViewState restoration happens during the Page_Init event. Yes, the ViewState is base-64 encoded.
What are the three Register directive attributes used to add custom controls to a Web form?

TagPrefix: The TagPrefix defines a unique namespace for an user control. If multiple user controls are present on the page having same name, then they can be differentiated with them by using this directive. It determines the group that the user control belongs to.

Namespace: It is nothing but the project name and namespace within the custom control assembly that contains the controls to register. The .NET applications use the project name as an implicit namespace for controls present in the application.

Assembly: This defines the name of the created assembly (.dll) that contains the custom controls. The control assembly is referenced by the Web application and it maintains a copy in the web applications 'Bin' directory.
What are composite custom controls?

Creating an extreme powerful control that is composite custom control which requires the combination of several server or HTML controls with in a single control class, and which can compiled with other control classes to create an assembly. That created assembly (.dll) contains custom control library. After creating, you can load into Visual Studio .NET and can use as how you are using standard controls.

These controls are functionally similar to user controls, but they present in their own assemblies, so you can share the same control in different projects without copying the control. However it’s difficult to create custom controls because you can’t draw them visually with the help of Visual Studio .NET.
What is difference between “Common Type System” and “Type Safe”?

CTS define all of the basic types that can be used in the .NET Framework and the operations performed on those types.

Type safe means preventing programs from accessing memory outside the bounds of an object's public properties. Type-safe code accesses only the memory locations which is authorized to access.
What is the use of MaintainScrollPositionOnPostBack property?

When a page is posted back to the server, at that time the user is at top position of the page rather it is not redirecting to that location where the user is before redirect of the webpage. So the use of MaintainScrollPositionOnPostBack property for a Page is to set the value as true or false for scroll position in the browser after the page is postback. When the property is set to true then the user will at that position at which the user is present before redirect. So we can say the user will redirect to the same position before redirect to another page.

<asp:Page MaintainScrollPositionOnPostBack="True/False" />

In which way you can retrieve original request URL when using URL rewriting or Server.Transfer in ASP.NET?

The way to retrieve original request URL is Request.ServerVariables("HTTP_X_REWRITE_URL") . It will work on all types of URL rewriting methods like ISAPI filters, HTTP Handlers or Http Modules and on Server.Transfer. Before any URI modifications, the original Request URI is saved into the HTTP header i.e. X-Rewrite-URL. This can also be retrieved in ASP.NET by using the above method.
How to follow the best way to secure connection strings in an ASP.NET web application?

• When you are working with ASP.NET applications, you should always store the connection strings in Web.config file. This is very secure. No user has rights to access web.config file from the browser.

• Store the connection strings as encrypted format in the configuration file.

• Don't store the connection strings in .aspx page.

• It is not recommended to set connection strings as declarative properties of the SqlDataSource control or some other data source controls.
What's the use of "Connecting to SQL Server using Integrated Security"?

This is best suited to use instead of using an explicit user name and password, which helps us to avoid the possibility of the connection string being compromised and your user ID and password being exposed.
Why we are storing an XML file in the applications App_Data folder?

The use of storing an XML file in App_Data folder is not to return the contents of the App_Data folder in response to direct HTTP requests.
Write the steps to avoid Script Injection attacks?

Step-1: First encode the user input with the HtmlEncode methods so that the method will return HTML into its text representation.

Step-2: When you are using bound fields of a Data controls, then set the BoundField object's HtmlEncode property to true which causes the Data control to encode input given by the user when you are in edit mode of that Data control.
What is an HTTP Handler?

This is a process which runs in response to a request made by an ASP.NET Web application. This is also referred to as endpoint. The ASP.NET page handler processes .aspx files. When a user requests an .aspx file, then the request is processed by the page through the page handler. It is also possible to create an HTTP handler that render custom output to the browser.
What is HTTP module?

These are the assemblies, and when you are sending any requests to your application then this assembly will call. This is also a part of the ASP.NET request pipeline and has access to life-cycle events throughout the request. HTTP modules are examining the incoming and outgoing requests and it takes action based on the request made by user.
What is the interface that you have to implement to create a Custom HTTP Handler?

• Implement IHttpHandler interface to create a synchronous handler.
• Implement IHttpAsyncHandler to create an asynchronous handler.
What is the difference between Synchronous and Asynchronous HTTP Handlers?

When you call for a HTTP request, unless until it finished the processing of assigned task, the Synchronous HTTP handler doesn't return any value. It will return a value after successful execution of sent request.

But in case of asynchronous handler, it will run a process independently and it will send a response to the end user. When you are working with some lengthy application processes, then it is advisable to use Asynchronous handler. Here the user doesn't need to wait until it finishes before receiving a response from the server.
How can you create your own custom HTTP handler factory class?

Yes, with the help of class by implementing the IHttpHandlerFactory interface, you can create your own custom HTTP handler factory class.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories