We need to enable “cookieless” property in Web.config.
2. How can we force all the validation control to run?
3. How can we check if all the validation control are valid and proper?
Using the Page.IsValid() property you can check whether all the validation are done.
4. If client side validation is enabled in your Web page, does that mean server side code is not run?
6. How to disable client side script in validators?
Set EnableClientScript property to false.
7. You find that one of your validation is very complicated and does not fit in any of the validators, what will you do ?
Best is to go for CustomValidators. Below is a sample code for a custom validator which checks that a textbox should not have zero value.
8. How can I show the entire validation error message in a message box on the client side?
In ValidationSummary control set property called “ShowMessageBox” to true.
9. What is Tracing in ASP.NET?
Tracing allows us to view how the code was executed in detail.
10. How do we enable tracing?
On the Application level we can add directive <trace enabled="true" to the web.config between … directives. On the page level we can add Trace =”true” to the @Page directive in the beginning of the page.
11. What exactly happens when ASPX page is requested from Browser?
- The browser sends the request to the webserver. Let us assume that the webserver at the other end is IIS.
- Once IIS receives the request he looks on which engine can serve this request. When I mean engine means the DLL who can parse this page or compile and send a response back to browser. Which request to map to is decided by file extension of the page requested. Depending on file extension following are some mapping: .aspx for ASP.NET Web pages, .asmx for ASP.NET Web services, .config for ASP.NET configuration files, .ashx for custom ASP.NET HTTP handlers, .rem for remoting resources etc.
- Once IIS passes the request to ASP.NET engine page has to go through two section HTTP module section and HTTP handler section. Both these section have their own work to be done in order that the page is properly compiled and sent to the IIS.
HTTP modules inspect the incoming request and depending on that they can change the internal workflow of the request. HTTP handler actually compiles the page and generates output. If you see your machine.config file you will see section of HTTP modules.
- HTTP handler is where the actual compilation takes place and the output is generated. HTTP handler section is present in WEB.CONFIG file. Depending on the File extension handler decides which Namespace will generate the output. Example all .ASPX extension files will be compiled by System.Web.UI.PageHandlerFactory
- Once the file is compiled it will be send back again to the HTTP modules and from there to IIS and then to the browser.
12. How can we kill a user session?
We can use Session.Abandon directive.
13. How do you upload a file in ASP.NET?
The code snippet given below enables you to upload a file to a folder named temp on your server:
string strdir = “D:\\temp\\”;
string strfilename = Path.GetFileName( txtFile.PostedFile.
Make sure to create the specified folder and change the path before attempting to execute the program. In the above code, you can the HTML File control so that users can browse for the required file. As you may know, an HTML control can be converted into an ASP.NET server control with the addition of the runat = “server” attribute. The system retrieves and saves the file using the PostedFile property. Because the HTML file control is used, you have to specifically give the enctype attribute of the Form tag:None found.