Thursday, July 2, 2009

ASP .NET Questions


What is the difference between Session_Start and Application_BeginRequest in Global.asax file?

Session_Start and Application_Begin Request events are fired every time a new user request is generated. However the difference is - Application_BeginRequest is fired when a request comes into the server and before the request is processed by the server. Session_Start is fired when a user request is being processed.

What happens when a user requests to view the Web.config file on the browser by typing the url : http:///web.config?

Web.config is managed by the IIS and when a web.config file is requested, the IIS throws an 'Access Denied" error.

How do you postback a page say A.aspx to another page B.aspx?

In the properties of button on page A.aspx, set the postbackurl = "~/B.aspx'"

How do you know that a Page is accessed due to Cross Page Posting?

IsCrossPagePostBack = true when the page is accessed due to Cross Page PostBack.

How do you access the controls on the Previous Page?

Use the PreviousPage.FindControl("ControlName") property to find the controls on Previous Page.

Is it possible to use two different languages say VB.NET and C# in a single application?

Yes. Create two different folders say VB and CS under the App_Code folder and put similar files in respective folders.
In Web.config create an entry for these folders as follows:
<compilation>
<codesubdirectories>
<add directoryname="VB"> </add>
<add directoryname="CS" >
</add>
</codesubdirectories >
</compilation>

What is the difference between Page.ClientScript.RegisterStartupScript and Page.ClientScript.RegisterClientScriptBlock?

Page.ClientScript.RegisterClientScriptBlock places the JavaScript function at the top of the page. This means that the script is in place for the startup of the page in the browser.

Page.ClientScript.RegisterStartupScript places the JavaScript function at the bottom of the ASP .NET page.

What is Page.ClientScript.RegisterClientScriptInclude?

Javascript (.js) files can be registered using Page.ClientScript.RegisterClientScriptInclude.

What is the difference between PostBack and CallBack ?

In PostBack, an HTTP Post request is sent to the web server which then processes the request with IPostBackEventHandler and runs the request through a series of page events like loading state, processing data, processing post back events, rendering page. This process completely reloads the page in the browser.

In CallBack scenario, an Asynchronous request is sent to the web server which then processes the request with ICallBackEventHandler which skips larger steps like Page Rendering. The result is returned to the script callback object. The script code then pushes the data into web page using JavaScript's capabilities to do this without refreshing the page.

What control is used to upload the files to the server? Are there any size limitations for the file?

FileUpload control is used to upload the files to the server. Maximum size of file that can be uploaded is 4MB. To make changes to the allowed file size, add a <httpRuntime> element to the web.config and set the maxRequestLength property to to the required size.


How to diable validation for the controls on a page?

Set CausesValidation = False in the button property.

How do I display the validation summary in a message box?

Set the property ShowMessage ="'True" in the ValidationSummary Control.

How to call the validation functions in a CustomValidator?

In CustomValidator, set the ClientSideValidationFunction and OnServerValidate properties to the Client side and Server side function names respectively.

At what stage are Master and Content file merged?

In Page_PreInit stage of the Content page, the Master and Content files are merged. Hence you can set a new master page for a Content Page in Page_PreInit stage.

At what stage can changes be made to Master file?

Page_Load of Content Page is fired before the Page_Load of Master Page. So to get anything initialized on Master Page, use Page_LoadComplete of the Content Page.


What is the difference between Theme and StyleSheetTheme?

Theme and StyleSheetTheme are the same other than that Themes override the local settings while StyleSheetThemes do not override the local settings.

What is the precedence of Themes in Master - Content Pages?

Theme specified in Master Page Theme takes precedence over the Content Pages.


No comments:

Post a Comment