Tuesday, 25 June 2013

asp dot net,asp,asp.net,3.5

What’ is the sequence in which ASP.NET events are processed?

Following is the sequence in which the events occur:-
• Page_Init.
• Page Load.
• Control events
• Page- Unload event.
Page_init event only occurs when first time the page is started, but Page Load occurs in subsequent request of the page.

In which event are the controls fully loaded?


Page load event guarantees that all controls are fully loaded. Controls are also accessed in Page_Init events but you will see that view state is not fully loaded during this event.5

 How can we identify that the Page is Post Back?
Page object has an “IsPostBack” property, which can be checked to know that is the page posted back.

What is event bubbling?


Server controls like Data grid, Data List, and Repeater can have other child controls inside them. Example Data Grid can have combo box inside data grid. These child control do not raise there events by themselves, rather they pass the event to the container parent (which can be a data grid, data list, repeater), which passed to the page as “ItemCommand” event. As the child control send events to parent it is termed as event bubbling.

 How do we assign page specific attributes?

Page attributes are specified using the @Page directive.

How do we ensure view state is not tampered?


Using the @Page directive and setting ‘EnableViewStateMac’ property to True.

What is the use of @ Register directives?


@Register directive informs the compiler of any custom server control added to the page.

What is the use of Smart Navigation property?


It’s a feature provided by ASP. NET to prevent flickering and redrawing when the page is posted back.
Note:- This is only supported for IE browser. Project is who have browser compatibility as requirements have to think some other ways of avoiding flickering.

What is AppSetting Section in “Web.Config” file?


Web.config file defines configuration for a web project. Using “AppSetting” section, we can define user-
defined values. Example below defined is “Connection String” section, which will be used through out the project for database connection.
<Configuration>
<appSettings>
<add key="ConnectionString" value="server=xyz;pwd=www;database=testing" />
</appSettings>

Where is View State information stored?


In HTML Hidden Fields.

How can we create custom controls in ASP.NET?


User controls are created using .ASCX in ASP.NET. After .ASCX file is created you need to two things in order that the ASCX can be used in project:.

• Register the ASCX control in page using the <percentage@ Register directive.Example

<%@ Register tag prefix="Accounting" Tag name="footer" Src="Footer.ascx" %>

• Now to use the above accounting footer in page you can use the below directive.

<Accounting: footer runat="server" />

How many types of validation controls are provided by ASP.NET?


There are six main types of validation controls:-

RequiredFieldValidator

It checks whether the control have any value. It is used when you want the control should not be empty.

RangeValidator

It checks if the value in validated control is in that specific range. Example TxtCustomerCode should not be more than eight lengths.

CompareValidator

It checks that the value in controls should match some specific value. Example Textbox TxtPie should be equal to 3.14.

RegularExpressionValidator

When we want the control, value should match with a specific regular expression.

CustomValidator
It is used to define User Defined validation.
Validation Summary
It displays summary of all current validation errors on an ASP.NET page.
Note: - It is rare that some one will ask step by step all the validation controls. Rather they will ask for what type of validation which validator will be used. Example in one of the interviews i was asked how will you display summary of all errors in the validation control...just uttered one word Validation summary.

Can you explain “AutoPostBack”?


If we want the control to automatically post back in case of any event, we will need to check this attribute as true. Example on a Combo Box change we need to send the event immediately to the server side then set the “AutoPostBack” attribute to true.

 How can you enable automatic paging in Data Grid?


Following are the points to be done in order to enable paging in Data grid:-
• Set the “Allow Paging” to true.
• In PageIndexChanged event set the current page index clicked.
Note: - The answers are very short, if you have implemented practically its just a revision. If you are fresher, just make sample code using Datagrid and try to implement this functionality.

What is the use of “GLOBAL.ASAX” file?


It allows to execute ASP.NET application level events and setting application-level variables.

What is the difference between “Web.config” and “Machine.Config”?


“Web.config” files apply settings to each web application, while “Machine.config” file apply settings to allASP.NET applications.

What is a SESSION and APPLICATION object?


Session object store information between HTTP requests for a particular user, while application object are global across users.

 Do session use cookies?


Twist:- How can we make session to not to use cookies ?
Left to the user, you will enjoy to find this answer.

How can we force all the validation control to run?


Page.Validate

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.

If client side validation is enabled in your Web page, does that mean server side code is not run.


When client side validation is enabled server emit’s JavaScript code for the custom validators. However, note that does not mean that server side checks on custom validators do not execute. It does this redundant check two times, as some of the validators do not support client side scripting.

Which JavaScript file is referenced for validating the validators at the client side?


WebUIValidation.js JavaScript file installed at “aspnet_client” root IIS directory is used to validate the validation controls at the client side

How to disable client side script in validators?


Set ‘EnableClientScript’ to false

How can I show the entire validation error message in a message box on the client side?


In validation summary set “ShowMessageBox” to true.

You find that one of your validations 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
<asp:CustomValidator id="CustomValidator1" runat="server"
ErrorMessage="Number not divisible by Zero"
ControlToValidate="txtNumber"
OnServerValidate="ServerValidate"
ClientValidationFunction="CheckZero" /><br>
Input:
<asp:TextBox id="txtNumber" runat="server" />
<script language="javascript">
<!--function CheckZero(source, args) {
int val = parseInt(args.Value, 10);
if (value==0) {
args.
IsValid = false;
}
}
// -->
</script>

What exactly happens when ASPX page is requested from a browser?

Note: - Here the interviewer is expecting complete flow of how an ASPX page is processed with respect to IIS and ASP.NET engine.
Following are the steps which occur when we request a ASPX page :-
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 we 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
You can also configure the extension mapping to which engine can route by using the IIS engine.


Figure: - 7.1 following screen shows some IIS mappings
Example an ASP page will be sent to old classic ASP.DLL to compile. While .ASPX pages will be routed toASP.NET engine for compilation.
• As this book mainly will target ASP.NET we will look in to how ASP.NET pages that is ASPX pages generation sequence occurs. 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 there 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 following section of HTTP modules

<httpModules>
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
<add name="Session" type="System.Web.SessionState.SessionStateModule" />
<add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" />
<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
<add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule" />
<add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
<add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" />
<add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule,
System.Web.Mobile, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</httpModules>


The above mapping will show which Namespace handles which functionality. Example FormsAthuentication is handled by “System. Web.
Security.FormsAuthenticationModule”. If you look at the web.config, section HTTP module is where authentication and authorization happens.

Ok now the HTTP handler is where the actual compilation takes place and the output is generated. Following is a paste from HTTP handler section of WEB.CONFIG file.
<httpHandlers>
<add verb="*" path="*.vjsproj" type="System.Web.HttpForbiddenHandler" />
<add verb="*" path="*.java" type="System.Web.HttpForbiddenHandler" />
<add verb="*" path="*.jsl" type="System.Web.HttpForbiddenHandler" />
<add verb="*" path="trace.axd" type="System.Web.Handlers.TraceHandler" />
<add verb="*" path="*.aspx" type="System.Web.UI.PageHandlerFactory" />
<add verb="*" path="*.ashx" type="System.Web.UI.SimpleHandlerFactory" />
...
</httpHandlers>

• 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.


Figure: - 7.2 IIS flow from various sections.

How can we kill a user session?


Session abandon

How do I send email message from ASP.NET?


ASP.NET provides two namespace SystemWEB.mailmessage class and System.Web.Mail.Smtpmail class. Just a small homework creates a Asp.NET project and send a email at shiv_koirala@yahoo.com. Do not Spam.

What are different IIS isolation levels?


IIS has three level of isolation:-
LOW (IIS process):- In this main IIS, process, and ASP.NET application run in same process. So if any one crashes the other is also affected. Example let us say (well this is not possible) I have hosted yahoo, hotmail .amazon and goggle on a single PC. So all application and the IIS process runs on the same process. In case any website crashes, it affects every one.
Figure: - 7.3 LOW IIS process scenario

Medium (Pooled):- In Medium pooled scenario, the IIS, and web application run in different process. Therefore, in this case there are two processes process1 and process2. In process1, the IIS process is running and in process2, we have all Web application running
Figure: - 7.4 Medium pooled scenario
High (Isolated):-In high isolated scenario every process is running is there own process. In below figure there are five processes and every one handling individual application. This consumes heavy memory but has highest reliability.
Figure: - 7.5 High isolation scenario

Can you explain Forms authentication in detail?


In old ASP if you where said to create a login page and do authentication you have to do hell lot of custom coding. Now in ASP.NET that has made easy by introducing Forms authentication. So let us see in detail what form authentication is.
Forms authentication uses a ticket cookie to see that user is authenticated or not. That means when user is authenticated first time a cookie is set to tell that this user is authenticated. If the cookies expire then Forms authentication mechanism sends the user to the login page.
Following are the steps, which defines steps for Forms authentication:-
• Configure Web.config file with forms authentication. As shown below in the config file you can see we have give the cookie name and loginurl page.
<configuration>
<system.web>
<!-- Other settings omitted. -->
<authentication mode="Forms">
<forms name="logincookies"
loginUrl="login.aspx"
protection="All"
timeout="30"
path="/" />
</authentication>
</system.web>
</configuration>

• Remove anonymous access to the IIS web application, following are changes done to web.config file.

<configuration>
<system.web>
<!-- Other settings omitted. -->
<authorization>
<deny users="?" />
</authorization>
</system.web>
</configuration>
• Create the login page, which will accept user information. You will have create your login page that is the Login.aspx, which will actually take the user data.
• Finally a small coding in the login button.
Let us assume that the login page has two textboxes TX name and txtapssword.
Also, import System.Web.Security and put the following code in login button of the page.
If Page.IsValid Then
If FormsAuthentication.Authenticate(txtName.Text, txtPassword.Text) Then
FormsAuthentication.RedirectFromLoginPage(txtName.Text, False)
Else
lblStatus.Text = "Error not proper user"
End If
End If

How do I sign out in forms authentication?


FormsAuthentication.Signout ()

If cookies are not enabled at browser end does form Authentication work?


No, it does not work.

How to use a checkbox in a data grid?


Twist: - How can I track event in checkbox, which is one of the columns of a data grid?
Note: - This is normally asked when the interviewer want to see that have you really worked practically on a project.

Following are the steps to be done:-
• In ASPX page you have to add Item template tag in data grid.
<ItemTemplate>
<asp:CheckBox id="CheckBox1" runat="server" AutoPostBack="True" OnCheckedChanged="Check_Clicked"></asp:CheckBox>
</ItemTemplate>

If you look at the Item template, we have “OnCheckChanged” event. This “OnCheckChanged” event has “Check Clicked” subroutine is actually in behind code. Note this method, which is in behind code, should either be “protected” or “public”
Following below is the subroutine, which defines the method
Protected Sub Check Clicked (By Val sender As Object, By Val e As EventArgs)
‘Do something
End Sub

The above steps should be defined in short to the interviewer, which will give a quick feeling of your practical experience with ASP.NET