Monday, August 10, 2009

Query XML Data in Sql 2005

1. Sql Server 2005 includes subset of the XQuery language

2. Xquery is a language for query data stored using Xml Data Type

3. DDL operation on xml column

Syntax to retrieve a date from a column of xml data type<
Select columnname .query (‘/nodename’) from TableName
Select columname .query (‘/nodename/childnodename’) from TableName
Note: other clause of select such as ’ where’ clause can be use in above
statements and column should be xml type nodename refer to element name
4. DML operation on Xml



* INSERT


Syntax : Insert into tablename (columname,Xmlcolumname) values (1
,”Xquery”)
Note :xmlcolumn name can be second or third column according to table definition and valid xml data should be inserted in xml column

* UPDATE


I)as first II) as last III)into Iv)after V)before VI)Delete VII)Replace value of

As Last & As First

Syntax:Update table name set columnname.modify(‘insert microsoft
as last into (/book[1]) ’)
Note: as last and as first same syntax .column should be xml type

After & before

Syntax:Update table name set columname.modify(‘insert james
after into (book /pubs[1]) ’)
Note: after and before same syntax .column should be xml type

Delete

Syntax:Update table name set columname.modify(‘ delete /book/pubs/auother ’)
Note:Enter element name with path colum should be xml type

Replace value of particular element

Syntax:Update table name set columname.modify(‘ replace value of
(book /pubs/text())[1] with ‘‘sql’’ ’)
Note:Enter element name with path colum & text() colum should be xml type


Refered links
http://msdn.microsoft.com/en-us/library/ms345122(SQL.90).aspx
http://msdn.microsoft.com/en-us/library/ms971534.aspx
http://msdn.microsoft.com/en-us/library/ms345117.aspx
http://blogs.msdn.com/mrorke/archive/2005/04/13/407921.aspx

new Features of Asp.net 3.5

# Asp.net Ajax is integerated in to dot netframwork

# Asp.net Ajax control extender can be added to toolbox vs2008

# Listview and datapager are new controls are added

# New Data source control is added called as Linq DataSource

# LINQ(language Integrated query) add native date query capapbilty to c#.net

# WCF Support for RSS, JSON, POX and Partial Trust

# Asp.net 3.5 include a new mergertool(aspnet_merge.exe).it comination and manage assemblies created by aspnet_compiler.exe(In older version it is avilable as addon)

# new Assemblies 3.5


1. System.core.dll-Includes the implementation for LINQ to objects

2. System.data.linq.dll-Include the implementaion for LINQ to SQL

3. System.Xml.Linq.dll-Include the implementation for LINQ to XMl

4. System.Date.DatsetExtension.dll-Includes implementation for LINQ to DataSet


# Asp.net 3.5 provide bettter support iis7 , iis7 Asp.net 3.5 modules and handles support unified configuration

# vs2002 worked with asp.net 1.0,vs2003 worked with Asp.net 1.1 and vs2005 worked with Asp.net 2.0 and Vs2008 support multiTargetting i.e it works with Asp.net 2.0 and Asp.net 3.5

Differencce between .net 2.0 ,3.0,3.5

Differencce between .net 2.0 ,3.0,3.5
.NET 2.0

CLR VERSION 2.0
FRMEWORK LIBRARIES : .NETfx 2.0
LANGUAGE : C# 2.0 VB 8.0
• A new hosting API for native applications wishing to host an instance of the .NET runtime
• Full 64-bit support for both the x64 and the IA64 hardware platforms.
• Language support for Generics built directly into the .NET CLR.
• Many additional and improved ASP.NET web controls.
• New data controls with declarative data binding.
• New personalization features for ASP.NET, such as support for themes, skins and webparts.

.NET 3.0

CLR VERSION 2.0
FRMEWORK LIBRARIES : .NETfx 3.0
LANGUAGE : C# 2.0 VB 8.0
• Windows Presentation Foundation (WPF), formerly code-named Avalon; a new user interface subsystem and API based on XML and vector graphics, which will make use of 3D computer graphics hardware and Direct3D technologies.
• Windows Communication Foundation (WCF), formerly code-named Indigo; a service-oriented messaging system which allows programs to interoperate locally or remotely similar to web services.
• Windows Workflow Foundation (WWF) allows for building of task automation and integrated transactions using workflows.
• Windows CardSpace (WCS), formerly code-named InfoCard; a software component which securely stores a person's digital identities and provides a unified interface for choosing the identity for a particular transaction, such as logging in to a website.

.NET 3.5

CLR VERSION 2.0
FRMEWORK LIBRARIES : .NETfx 3.5
LANGUAGE : C# 3.0 VB 9.0
.NET 2.0 contains CLR.WINFORMS,ASPNET
.NET 3.0 contains complete .net 2.o and WCF,WPF,WF,CARD SPACE
.NET 3.5 contains complete .net 3.0 and LINQ , AJAX
langauage integrty query (LINQ): it is microsoft .net framwork component adds data native querying capabilities to .net languages using systnax reminiscent of sql

Thursday, March 26, 2009

Change in Behavior of RAND and NEWID in SQL Server 2005

I’m writing this blog entry as a result of a customer query regarding a change
in behavior related to invocations of the RAND and NEWID functions in
SQL Server 2005.

Suppose you need to write an expression in a query invoking the RAND or
NEWID function (say for randomization purposes) and you need the
function to be invoked only once. For example, suppose you need to make
a random choice out of three options (call them ‘option one’, ‘option two’
and ‘option three’), and you write the following code:


select
case rnd
when 1 then 'option one'
when 2 then 'option two'
when 3 then 'option three'
else 'oops'
end
from (select cast(rand()*3 as int)%3 + 1 as rnd) as d;
Remember that the RAND function returns a float value in the range 0
through 1, inclusive (0 and 1 are possible result values). Casting the
expression rand()*3 as an integer will truncate the fraction part of the value.

Even though the probability to get exactly 3 back after casting is very low, it
is still a possibility. This is why I used %3 (modulo 3)—to ensure the
expression will return an integer in the range 0 through 2. By adding 1, the
expression is guaranteed to return an integer in the range 1 through 3.

Internally, SQL Server rearranges a simple form of a CASE expression
such as the above to the searched form, namely, it expands the WHEN
clauses to incorporate the full predicates. As an example, the above CASE
expression is internally evaluated as follows:

select
case
when rnd = 1 then 'option one'
when rnd = 2 then 'option two'
when rnd = 3 then 'option three'
else 'oops'
end
from (select cast(rand()*3 as int)%3 + 1 as rnd) as d;
SQL Server 2000 evaluates each reference to the alias rnd assigned in the
table expression d separately; therefore, it actually invokes the RAND
function three times. You realize that this means that in SQL Server 2000 it
is possible that none of the WHEN clauses of the CASE expression will
evaluate to TRUE, and you might end up getting ‘oops’ back. Try running this
code several times in SQL Server 2000 and you will be able to verify this.

SQL Server 2005 changes the behavior of outer references to aliases
assigned in table expressions, where the aliased expression invokes the
RAND or NEWID function. SQL Server 2005 will invoke the function only
once, therefore it is guaranteed that one of the WHEN clauses in the above
query will evaluate to TRUE, and you will never get ‘oops’ back.

You can test this with a similar example that invokes the NEWID function.
To return a random value in the range 1 through n, instead of using the
expression:

cast(rand()*n as int)%n + 1
You can use the expression:

abs(checksum(newid()))%n + 1
CHECKSUM(NEWID()) returns a random integer. Applying ABS on top
ensures you get a nonnegative integer. Applying %n (modulo n) ensures that
the value is >= 0 and < n. By adding 1 you ensure that the value is >= 1 and
<= n. In short, this is just another way to get a random integer value in the
range 1 through n. So the above query can be rewritten as follows:

select
case rnd
when 1 then 'option one'
when 2 then 'option two'
when 3 then 'option three'
else 'oops'
end
from (select abs(checksum(newid()))%3 + 1 as rnd) as d;
Try running this query several times in both SQL Server 2000 and in SQL
Server 2005. In SQL Server 2000 you will occasionally get ‘oops’ back,
while in SQL Server 2005 you will never get ‘oops’ back. This is due to the
same change in behavior I described earlier.

A simple way to test the difference in behavior between the versions is by
running the following code:

select rnd, rnd
from (select rand() as rnd) as d;
Run it in SQL Server 2000 and you will get two different invocations of
RAND, hence most probably two different values back. Run it in SQL
Server 2005, and you’re guaranteed to get the same value back twice since
RAND will be invoked only once.

This change is described in SQL Server 2005’s Books Online under the
section “Behavior Changes to Database Engine Features in SQL Server
2005,” but it’s very easy to overlook it.

Note that the change in behavior has nothing to do with multiple invocations
of RAND or NEWID in the same query, as opposed to being invoked once
in a table expression and then referenced multiple times in the outer query.
For example, the following code can return ‘oops’ in both SQL Server 2000
and in SQL Server 2005:

select
case abs(checksum(newid()))%3 + 1
when 1 then 'option one'
when 2 then 'option two'
when 3 then 'option three'
else 'oops'
end;
In SQL Server 2005 you can now use a table expression as demonstrated
earlier as a workaround. In SQL Server 2000 (and also in 2005), you can
use a variable as a workaround:

declare @rnd as int;
set @rnd = abs(checksum(newid()))%3 + 1;

select
case @rnd
when 1 then 'option one'
when 2 then 'option two'
when 3 then 'option three'
else 'oops'
end;
You can experience similar problems in less obvious scenarios; for example,
consider the predicate:
where abs(checksum(newid()))%3 + 1 between col1 and col2
Also here, the predicate is expanded internally and NEWID is invoked multiple times:

where col1 >= abs(checksum(newid()))%3 + 1
and col2 <= abs(checksum(newid()))%3 + 1
So you end up getting two independent invocations of the NEWID function.
If you want to rely on a single invocation, as demonstrated earlier in SQL
Server 2005 you can use a table expression, and in both versions you can
store the result of the expression in a variable and then refer to the variable.

As the last example of problematic use of RAND and NEWID, I recently
saw code written by a programmer that was supposed to populate a
temporary table with a set of unique random integers (say, 50 random
integers in the range 1 through 100). The code looked similar to the
following:

set nocount on;
create table #random_values(rnd int not null);
create index idx1 on #random_values(rnd);

declare @i as int;
set @i = 1;
while @i <= 50
begin
insert into #random_values
select abs(checksum(newid()))%100 + 1
where abs(checksum(newid()))%100 + 1
not in (select rnd from #random_values);
if @@rowcount = 1 set @i = @i + 1;
end

select rnd from #random_values order by rnd;

drop table #random_values;
You realize that the two invocations of the NEWID function (in the
SELECT and WHERE clauses) are independent of each other. Therefore,
this code may very well populate the temporary table with duplicate values
in all versions of SQL Server. For example, here’s a subset of the output I
got after running this code:

rnd
-----------
2
3
4
4
...
I’m not saying that this particular solution is the optimal way to get a set of
unique random values rather just explaining the logical problems with this
solution and the workarounds.

In SQL Server 2005 you can now use a table expression as a workaround,
revising the SELECT query to the following:

...
insert into #random_values
select rnd
from (select abs(checksum(newid()))%100 + 1 as rnd) as d
where rnd not in (select rnd from #random_values);
...
In both SQL Server 2000 and 2005 you can use a variable as a workaround:

...
set @rnd = abs(checksum(newid()))%100 + 1;
insert into #random_values
select @rnd
where @rnd not in (select rnd from #random_values);
...
To summarize, care should be taken when using functions such as RAND
and NEWID in queries. If you need to rely on a single invocation of the
function, SQL Server 2005 will give you the desired behavior as long as you
encapsulate the invocation of the function in a table expression and then in
the outer query refer to the alias of the expression as many times as you like.
In SQL Server 2000 (or any other version), you can use a variable as a
workaround.

Thanks
Srini Reddy

Change in Behavior of RAND and NEWID in SQL Server 2005

I’m writing this blog entry as a result of a customer query regarding a change
in behavior related to invocations of the RAND and NEWID functions in
SQL Server 2005.

Suppose you need to write an expression in a query invoking the RAND or
NEWID function (say for randomization purposes) and you need the
function to be invoked only once. For example, suppose you need to make
a random choice out of three options (call them ‘option one’, ‘option two’
and ‘option three’), and you write the following code:


select
case rnd
when 1 then 'option one'
when 2 then 'option two'
when 3 then 'option three'
else 'oops'
end
from (select cast(rand()*3 as int)%3 + 1 as rnd) as d;
Remember that the RAND function returns a float value in the range 0
through 1, inclusive (0 and 1 are possible result values). Casting the
expression rand()*3 as an integer will truncate the fraction part of the value.

Even though the probability to get exactly 3 back after casting is very low, it
is still a possibility. This is why I used %3 (modulo 3)—to ensure the
expression will return an integer in the range 0 through 2. By adding 1, the
expression is guaranteed to return an integer in the range 1 through 3.

Internally, SQL Server rearranges a simple form of a CASE expression
such as the above to the searched form, namely, it expands the WHEN
clauses to incorporate the full predicates. As an example, the above CASE
expression is internally evaluated as follows:

select
case
when rnd = 1 then 'option one'
when rnd = 2 then 'option two'
when rnd = 3 then 'option three'
else 'oops'
end
from (select cast(rand()*3 as int)%3 + 1 as rnd) as d;
SQL Server 2000 evaluates each reference to the alias rnd assigned in the
table expression d separately; therefore, it actually invokes the RAND
function three times. You realize that this means that in SQL Server 2000 it
is possible that none of the WHEN clauses of the CASE expression will
evaluate to TRUE, and you might end up getting ‘oops’ back. Try running this
code several times in SQL Server 2000 and you will be able to verify this.

SQL Server 2005 changes the behavior of outer references to aliases
assigned in table expressions, where the aliased expression invokes the
RAND or NEWID function. SQL Server 2005 will invoke the function only
once, therefore it is guaranteed that one of the WHEN clauses in the above
query will evaluate to TRUE, and you will never get ‘oops’ back.

You can test this with a similar example that invokes the NEWID function.
To return a random value in the range 1 through n, instead of using the
expression:

cast(rand()*n as int)%n + 1
You can use the expression:

abs(checksum(newid()))%n + 1
CHECKSUM(NEWID()) returns a random integer. Applying ABS on top
ensures you get a nonnegative integer. Applying %n (modulo n) ensures that
the value is >= 0 and < n. By adding 1 you ensure that the value is >= 1 and
<= n. In short, this is just another way to get a random integer value in the
range 1 through n. So the above query can be rewritten as follows:

select
case rnd
when 1 then 'option one'
when 2 then 'option two'
when 3 then 'option three'
else 'oops'
end
from (select abs(checksum(newid()))%3 + 1 as rnd) as d;
Try running this query several times in both SQL Server 2000 and in SQL
Server 2005. In SQL Server 2000 you will occasionally get ‘oops’ back,
while in SQL Server 2005 you will never get ‘oops’ back. This is due to the
same change in behavior I described earlier.

A simple way to test the difference in behavior between the versions is by
running the following code:

select rnd, rnd
from (select rand() as rnd) as d;
Run it in SQL Server 2000 and you will get two different invocations of
RAND, hence most probably two different values back. Run it in SQL
Server 2005, and you’re guaranteed to get the same value back twice since
RAND will be invoked only once.

This change is described in SQL Server 2005’s Books Online under the
section “Behavior Changes to Database Engine Features in SQL Server
2005,” but it’s very easy to overlook it.

Note that the change in behavior has nothing to do with multiple invocations
of RAND or NEWID in the same query, as opposed to being invoked once
in a table expression and then referenced multiple times in the outer query.
For example, the following code can return ‘oops’ in both SQL Server 2000
and in SQL Server 2005:

select
case abs(checksum(newid()))%3 + 1
when 1 then 'option one'
when 2 then 'option two'
when 3 then 'option three'
else 'oops'
end;
In SQL Server 2005 you can now use a table expression as demonstrated
earlier as a workaround. In SQL Server 2000 (and also in 2005), you can
use a variable as a workaround:

declare @rnd as int;
set @rnd = abs(checksum(newid()))%3 + 1;

select
case @rnd
when 1 then 'option one'
when 2 then 'option two'
when 3 then 'option three'
else 'oops'
end;
You can experience similar problems in less obvious scenarios; for example,
consider the predicate:
where abs(checksum(newid()))%3 + 1 between col1 and col2
Also here, the predicate is expanded internally and NEWID is invoked multiple times:

where col1 >= abs(checksum(newid()))%3 + 1
and col2 <= abs(checksum(newid()))%3 + 1
So you end up getting two independent invocations of the NEWID function.
If you want to rely on a single invocation, as demonstrated earlier in SQL
Server 2005 you can use a table expression, and in both versions you can
store the result of the expression in a variable and then refer to the variable.

As the last example of problematic use of RAND and NEWID, I recently
saw code written by a programmer that was supposed to populate a
temporary table with a set of unique random integers (say, 50 random
integers in the range 1 through 100). The code looked similar to the
following:

set nocount on;
create table #random_values(rnd int not null);
create index idx1 on #random_values(rnd);

declare @i as int;
set @i = 1;
while @i <= 50
begin
insert into #random_values
select abs(checksum(newid()))%100 + 1
where abs(checksum(newid()))%100 + 1
not in (select rnd from #random_values);
if @@rowcount = 1 set @i = @i + 1;
end

select rnd from #random_values order by rnd;

drop table #random_values;
You realize that the two invocations of the NEWID function (in the
SELECT and WHERE clauses) are independent of each other. Therefore,
this code may very well populate the temporary table with duplicate values
in all versions of SQL Server. For example, here’s a subset of the output I
got after running this code:

rnd
-----------
2
3
4
4
...
I’m not saying that this particular solution is the optimal way to get a set of
unique random values rather just explaining the logical problems with this
solution and the workarounds.

In SQL Server 2005 you can now use a table expression as a workaround,
revising the SELECT query to the following:

...
insert into #random_values
select rnd
from (select abs(checksum(newid()))%100 + 1 as rnd) as d
where rnd not in (select rnd from #random_values);
...
In both SQL Server 2000 and 2005 you can use a variable as a workaround:

...
set @rnd = abs(checksum(newid()))%100 + 1;
insert into #random_values
select @rnd
where @rnd not in (select rnd from #random_values);
...
To summarize, care should be taken when using functions such as RAND
and NEWID in queries. If you need to rely on a single invocation of the
function, SQL Server 2005 will give you the desired behavior as long as you
encapsulate the invocation of the function in a table expression and then in
the outer query refer to the alias of the expression as many times as you like.
In SQL Server 2000 (or any other version), you can use a variable as a
workaround.

Thanks
Srini Reddy

Saturday, February 7, 2009

Ajax Interview Questions


Q1 - What is AJAX?



A - Ajax stands for Asynchronous Javascript & XML. It is a web technology through which a postback from a client (browser) to
the server goes partially, which means that instead of a complete postback, a partial postback is triggered by the Javascript
XmlHttpRequest object. In such a scenario, web-application users won't be able to view the complete postback progress bar
shown by the browser. In an AJAX environment, it is Javascript that starts the communication with the web server.


Ajax technology in a website may be implemented by using plain Javascript and XML. Code in such a scenario may tend to look
little complex, for which the AJAX Framework in .NET can be embedded in ASP.NET web applications.


In addition to XML & Javascript, AJAX is also based on DOM - the Document Object Model technology of browsers through which
objects of the browser can be accessed through the memory heap using their address.


JSON - Javascript Object Notation is also one of the formats used in AJAX, besides XML.


So basically, in an AJAX-based web application, the complete page does not need to reload, and only the objects in context of
ajaxification are reloaded.


Ajax technology avoids the browser flickering.




Q2 - Can Ajax be implemented in browsers that do not support the XmlHttpRequest object?



A - Yes. This is possible using remote scripts.



Q3 - Can AJAX technology work on web servers other than IIS?




A - Yes, AJAX is a technology independent of web server the web application is hosted on. Ajax is a client (browser)
technology.



Q4 - Which browsers support the XmlHttpRequest object?



A - Internet Explorer 5.0+, Safari 1.2, Mozilla 1.0/Firefox, Opera 8.0 +, Netscape 7



Q5 - How to we create an XmlHttpRequest object for Internet Explorer? How is this different for other browsers?



A - For Internet Explorer, an ActiveXObject is used for declaring an XmlHttpRequest object in Javascript.



//Code as below for IE:




xmlHttpObject = new ActiveXObject("Msxml2.XMLHTTP");



//For Other browsers, code as below:



xmlHttpObject = new XMLHttpRequest();





Note that XmlHttpObject used above is simply a variable that holds the XmlHttpRequest object for the respective browsers.



Q6 - What are the properties of the XmlHttpRequest object? What are the different types of readyStates in Ajax?



A - i) onreadyStateChange - This function is used to process the reply from the web server.



ii) readyState - This property holds the response status of the web server. There are 5 states:



0 - request not yet initialized



1 - request now set



2 - request sent



3 - request processing



4 - request completes



iii) responseText - Has the data sent back by the web server





Code snippet below shows an example how these there properties are used to implement ajax :



xmlHttpObject.onreadystatechange=function()

{

if(xmlHttpObject.readyState==4)

{

document.Form1.time.value=xmlHttpObject.responseText;

}

}




Q7 - What is the ASP.NET Ajax Framework? What versions have been released so far?



A - ASP.NET AJAX is a free framework to implement Ajax in asp.net web applications, for quickly creating efficient and
interactive Web applications that work across all popular browsers.



The Ajax Framework is powered with



1 - Reusable Ajax Controls



2 - Support for all modern browsers



3 - Access remote services and data from the browser without tons of complicated script.



Versions of Ajax release




1 - ASP.NET Ajax Framework 1.0 (earlier release to this was called the Atlas)

2 - ASP.NET Ajax Framework 1.0 was available as a separate download for ASP.NET 2.0



Q8 - What are Ajax Extensions?



A - The ASP.NET Ajax Extensions are set of Ajax-based controls that work in ASP.NET 2 (or above) based applications.



Ofcourse,they also need the Ajax runtime which is actually the Ajax Framework 1.0.



ASP.NET Ajax Extensions 1.0 have to be downloaded to run with ASP.NET 2.0



The new ASP.NET 3.5 Framework comes with the Ajax Library 3.5 (containing the Ajax Extensions 3.5). So in order to use the
latest Ajax, simply download .NET 3.5 Framework.



Summary :

ASP.NET Ajax Extensions 1.0 -> For ASP.NET 2.0

ASP.NET Ajax Extensions 3.5 -> For ASP.NET 3.5



Q9 - What is the ASP.NET Control Toolkit?



A - Besides the Ajax Framework (which is the Ajax engine) and Ajax Extensions (which contain the default Ajax controls),
there is a toolkit called the Ajax Control Toolkit available for use & download (for free). This is a collection of rich
featured, highly interactive controls, created as a joint venture between Microsoft & the Developer Community.



Q10 - What is Dojo?



A - Dojo is a third-party javascript toolkit for creating rich featured applications. Dojo is an Open Source DHTML toolkit
written in JavaScript. It builds on several contributed code bases (nWidgets, Burstlib, f(m)), which is why we refer to it
sometimes as a "unified" toolkit. Dojo aims to solve some long-standing historical problems with DHTML which prevented mass
adoption of dynamic web application development.



For more on Dojo, check this link: Click Here



Q11 - How to handle multiple or concurrent requests in Ajax?



A - For concurrent requests, declare separate XmlHttpRequest objects for each request. For example, for request to get data
from an SQL table1, use something like this...





xmlHttpObject1.Onreadystatechange = functionfromTable1();



and to get data from another table (say table2) at the same time, use



xmlHttpObject2.Onreadystatechange = functionfromTable2();



Ofcourse, the XmlHttpObject needs to be opened & parameters passed too, like as shown below...



xmlHTTPObject1.open("GET","http://"localhost// " + "Website1/Default1.aspx" true);



Note that the last parameter "true" used above means that processing shall carry on without waiting for any response from the
web server. If it is false, the function shall wait for a response.



Q12 - How to create an AJAX website using Visual Studio?



A - Using Visual Studio Web Developer Express 2005 & versions above
it, Ajax based applications may easily be created. Note that the
Ajax Framework & Ajax Extensions should be installed (In case of VS
2005). If using Visual Studio 2008 Web Developer Express or above,
Ajax comes along with it (so no need of a separate installation).



Steps: Start Visual Studio, Click on File -> New Website
-> Under Visual Studio Installed templates -> Select ASP.NET
Ajax-Enabled Site. Enter a location & select OK.



Q13 - What is the role of ScriptManager in Ajax?



A - ScriptManager class is the heart of ASP.NET Ajax. Before elaborating more on ScriptManager, note that ScriptManager
is class and a control (both) in Ajax.


The ScriptManager class in ASP.NET manages Ajax Script
Libraries, partial page rendering functionality and client proxy class
generation for web applications and services. By saying client proxy
class, this means an instance of the Ajax runtime is created on the
browser.


This class is defined in the System.Web.Extensions.dll. You will find this DLL in your system's Global Assembly Cache
at C:\Windows\Assembly (For XP)



The ScriptManager control (that we may drag on a web form) is actually
an instance of the ScriptManager class that we put on a web page.
The ScriptManager manages all the ASP.NET Ajax controls on a web page.
Following tasks are taken care by the ScriptManager class:

1 - Managing all resources (all objects/controls) on a web page

2 - Managing partial page updates

3 - Download Ajax Script Library to the client (means to the browser).
This needs to happen so that Ajax engine is accessible to the browsers
javascript code.

4 - Interacting with UpdatePanel Control, UpdateProgress Control.

5 - Register script (using RegisterClientScriptBlock)

6 - Information whether Release OR Debug script is sent to the browser

7 - Providing access to Web service methods from the script by registering Web services with the ScriptManager control

8 - Providing access to ASP.NET authentication, role, and profile application services from client script after
registering these services with the ScriptManager control

9 - Enable culture specific display of clientside script.

10 - Register server controls that implement IExtenderControl and IScriptControl interfaces.



ScriptManager class' EnablePartialRendering property is true by default.



Q14 - Can we override the EnablePartialRendering property of the ScriptManager class?



A - Yes. But this has to be done before the init event of the page (or
during runtime after the page has already loaded). Otherwise an
InvalidOperationException will be thrown.



Q15 - How to use multiple ScriptManager controls in a web page?


A - No. It is not possible to use multiple ScriptManager
control in a web page. In fact, any such requirement never comes in
because a single ScriptManager control is enough to handle the objects
of a web page.



Q16 - Whats the difference between RegisterClientScriptBlock, RegisterClientScriptInclude and RegisterClientScriptResource?



A - For all three, a script element is rendered after the opening form tag. Following are the differences:

1 - RegisterClientScriptBlock - The script is specified as a string parameter.

2 - RegisterClientScriptInclude - The script content is specified by
setting the src attribute to a URL that points to a script file.

3 - RegisterClientScriptResource - The script content is specified with
a resource name in an assembly. The src attribute is automatically
populated with a URL by a call to an HTTP handler that retrieves the
named script from the assembly.





Q17 - What are type/key pairs in client script registration? Can there be 2 scripts with the same type/key pair name?



A - When a script is registered by the ScriptManager class, a type/key pair is created to uniquely identify the script.




For identification purposes, the type/key pair name is always unique for dentifying a script. Hence, there may be no duplication
in type/key pair names.



Q18 - What is an UpdatePanel Control?



A - An UpdatePanel control is a holder for server side controls that need to be partial postbacked in an ajax cycle.
All controls residing inside the UpdatePanel will be partial postbacked. Below is a small example of using an UpdatePanel.




<script runat="server">


protected void btn1_Click(object sender, EventArgs e)

{

 lb123.Text = "new";

}

</script>



<asp:ScriptManager ID="ScriptManager1" runat="server">

  </asp:ScriptManager>

<asp:UpdatePanel ID="UpdatePanel1" runat="server">

  <ContentTemplate>

 <asp:Button id="btn1" runat="server" text="click"/>

<br/>

 <asp:Label id="lb123" runat="server" text="Old"/>

</ContentTemplate>

</UpdatePanel>




As you see here after running the snippet above, there wont be a full
postback exhibited by the web page. Upon clicking the button, the
postback shall be partial. This means that contents outside the
UpdatePanel wont be posted back to the web server. Only the contents
within
the UpdatePanel are refreshed.



Q19 - What are the modes of updation in an UpdatePanel? What are Triggers of an UpdatePanel?



A - An UpdatePanel has a property called UpdateMode. There are two possible values for this property: 1) Always 2) Conditional


If the UpdateMode property is set to "Always", the UpdatePanel
control’s content is updated on each postback that starts from anywhere
on the webpage. This also includes asynchronous postbacks from controls
that are inside other UpdatePanel controls, and postbacks from controls
which are not inside UpdatePanel controls.


If the UpdateMode property is set to Conditional, the
UpdatePanel control’s content is updated when one of the following is
true:


1 - When the postback is caused by a trigger for that UpdatePanel control.



2 - When you explicitly call the UpdatePanel control's Update() method.



3 - When the UpdatePanel control is nested inside another UpdatePanel control and the parent panel is updated.



When the ChildrenAsTriggers property is set to true and any child control of the UpdatePanel control causes a
postback. Child controls of nested UpdatePanel controls do not cause an update to the outer UpdatePanel control
unless they are explicitly defined as triggers for the parent panel.



Controls defined inside a <Triggers> node have the capability to update the contents of an UpdatePanel.




If the ChildrenAsTriggers property is set to false and the UpdateMode property is set to Always, an exception is
thrown. The ChildrenAsTriggers property is intended to be used only when the UpdateMode property is set to Conditional.



Q20 - How to control how long an Ajax request may last?



A - Use the ScriptManager's AsyncPostBackTimeout Property.



For example, if you want to debug a web page but you get an error that the page request has timed out, you may set

<asp:ScriptManager id="ScriptManager1" runat="server" AsyncPostBackTimeout="9000"/>



where the value specified is in seconds.



Q21 - What is ASP.NET Futures?



A -

ASP.NET AJAX Futures



The new release includes support for managing browser history (Back button support), selecting elements by CSS
selectors or classes, and information on accessing “Astoria” Web data services. The Futures (July 2007) release
adds:



History support for the Safari browser, inclusion of “titles”, encoding and encrypting of server-side history
state and the ability to handle history in the client without a server requirement.



CSS Selectors APIs have been modified to be applicable to W3C recommendations.

A
script resource extraction tool that allows you to create script files
on disk that originate from embedded resources in assemblies.
Important: this version of the browser history feature is now outdated
and should not be used. Instead, please download the ASP.NET 3.5
Extensions Preview, which contains the new version.


For More: Click Here



Q22 - What are limitations of Ajax?



A - 1) An Ajax Web Application tends to confused end users if the
network bandwidth is slow, because there is no full postback running.
However, this confusion may be eliminated by using an UpdateProgress
control in tandem.

2) Distributed applications running Ajax will need a central mechanism for communicating with each other




Q23 - How to make sure that contents of an UpdatePanel update only when
a partial postback takes place (and not on a full postback)?



A - Make use of ScriptManager.IsInAsyncPostBack property (returns a boolean value)



Q24 - How to trigger a postback on an UpdatePanel from Javascript?


A - Call the __doPostBack function. ASP.NET runtime always
creates a javascript function named __doPostBack(eventTarget,
eventArgument) when the web page is rendered.
A control ID may be passed here to specifically invoke updation of the
UpdatePanel.



Q25 - Which request is better with AJAX, Get or Post?



A - AJAX requests should use an HTTP GET request while retrieving data where the data does not change for a given
URL requested. An HTTP POST should be used when state is updated on the server. This is in line with HTTP idempotency
recommendations and is highly recommended for a consistent web application architecture.

Tuesday, December 30, 2008

Short Answer .NET Interview Questions

Q1. Explain the differences between Server-side
and Client-side code?

Ans. Server side code will
execute at server (where the website is hosted) end, & all
the business logic will execute at server end where as client
side code will execute at client side (usually written in
javascript, vbscript, jscript) at browser end.

Q2.
What type of code (server or client) is found in a Code-Behind
class?

Ans. Server side code.

Q3. How to
make sure that value is entered in an asp:Textbox
control?

Ans. Use a RequiredFieldValidator
control.

Q4. Which property of a validation control
is used to associate it with a server control on that
page?

Ans. ControlToValidate property.

Q5.
How would you implement inheritance using VB.NET & C#?

Ans. C# Derived Class : Baseclass
VB.NEt : Derived
Class Inherits Baseclass

Q6. Which method is
invoked on the DataAdapter control to load the generated
dataset with data?

Ans. Fill() method.

Q7.
What method is used to explicitly kill a user's session?

Ans. Session.Abandon()

Q8. What property
within the asp:gridview control is changed to bind columns
manually?

Ans. Autogenerated columns is set to false


Q9. Which method is used to redirect the user to
another page without performing a round trip to the
client?

Ans. Server.Transfer method.

Q10.
How do we use different versions of private assemblies in same
application without re-build?

Ans.Inside the
Assemblyinfo.cs or Assemblyinfo.vb file, we need to specify
assembly version.
assembly: AssemblyVersion


Q11. Is it possible to debug java-script in .NET
IDE? If yes, how?

Ans. Yes, simply write "debugger"
statement at the point where the breakpoint needs to be set
within the javascript code and also enable javascript
debugging in the browser property settings.

Q12. How
many ways can we maintain the state of a page?

Ans. 1.
Client Side - Query string, hidden variables, viewstate,
cookies
2. Server side - application , cache, context,
session, database

Q13. What is the use of a
multicast delegate?

Ans. A multicast delegate may be
used to call more than one method.

Q14. What is the
use of a private constructor?

Ans. A private
constructor may be used to prevent the creation of an instance
for a class.

Q15. What is the use of Singleton
pattern?

Ans. A Singleton pattern .is used to make
sure that only one instance of a class exists.

Q16.
When do we use a DOM parser and when do we use a SAX
parser?

Ans. The DOM Approach is useful for small
documents in which the program needs to process a large
portion of the document whereas the SAX approach is useful for
large documents in which the program only needs to process a
small portion of the document.

Q17. Will the finally
block be executed if an exception has not
occurred?

Ans.Yes it will execute.

Q18. What
is a Dataset?

Ans. A dataset is an in memory database
kindof object that can hold database information in a
disconnected environment.

Q19. Is XML a
case-sensitive markup language?

Ans. Yes.


Q20. What is an .ashx file?
Ans. It is a web
handler file that produces output to be consumed by an xml
consumer client (rather than a browser).

Short Answer .NET Interview Questions


Q21. What is encapsulation?
Ans.
Encapsulation is the OOPs concept of binding the attributes
and behaviors in a class, hiding the implementation of the
class and exposing the functionality.

Q22. What is
Overloading?

Ans. When we add a new method with the
same name in a same/derived class but with different
number/types of parameters, the concept is called overluoad
and this ultimately implements Polymorphism.

Q23.
What is Overriding?

Ans. When we need to provide
different implementation in a child class than the one
provided by base class, we define the same method with same
signatures in the child class and this is called overriding.


Q24. What is a Delegate?
Ans. A delegate is
a strongly typed function pointer object that encapsulates a
reference to a method, and so the function that needs to be
invoked may be called at runtime.

Q25. Is String a
Reference Type or Value Type in .NET?

Ans. String is a
Reference Type object.

Q26. What is a Satellite
Assembly?

Ans. Satellite assemblies contain resource
files corresponding to a locale (Culture + Language) and these
assemblies are used in deploying an application globally for
different languages.

Q27. What are the different
types of assemblies and what is their use?

Ans.
Private, Public(also called shared) and Satellite Assemblies.


Q28. Are MSIL and CIL the same thing?
Ans.
Yes, CIL is the new name for MSIL.

Q29. What is the
base class of all web forms?

Ans. System.Web.UI.Page


Q30. How to add a client side event to a server
control?

Ans. Example...
BtnSubmit.Attributes.Add("onclick","javascript:fnSomeFunctionInJavascript()");


Q31. How to register a client side script from
code-behind?

Ans. Use the
Page.RegisterClientScriptBlock method in the server side code
to register the script that may be built using a
StringBuilder.

Q32. Can a single .NET DLL contain
multiple classes?

Ans. Yes, a single .NET DLL may
contain any number of classes within it.

Q33. What
is DLL Hell?

Ans. DLL Hell is the name given to the
problem of old unmanaged DLL's due to which there was a
possibility of version conflict among the DLLs.


Q34. can we put a break statement in a finally
block?

Ans. The finally block cannot have the break,
continue, return and goto statements.

Q35. What is
a CompositeControl in .NET?

Ans. CompositeControl is an
abstract class in .NET that is inherited by those web controls
that contain child controls within them.

Q36. Which
control in asp.net is used to display data from an xml file
and then displayed using XSLT?

Ans. Use the asp:Xml
control and set its DocumentSource property for associating an
xml file, and set its TransformSource property to set the xml
control's xsl file for the XSLT transformation.


Q37. Can we run ASP.NET 1.1 application and ASP.NET
2.0 application on the same computer?

Ans. Yes, though
changes in the IIS in the properties for the site have to be
made during deployment of each.

Q38. What are the
new features in .NET 2.0?

Ans. Plenty of new controls,
Generics, anonymous methods, partial classes, iterators,
property visibility (separate visibility for get and set) and
static classes.

Q39. Can we pop a MessageBox in a
web application?

Ans. Yes, though this is done
clientside using an alert, prompt or confirm or by opening a
new web page that looks like a messagebox.

Q40.
What is managed data?

Ans. The data for which the
memory management is taken care by .Net runtime’s garbage
collector, and this includes tasks for allocation
de-allocation.

Q41. How to instruct the garbage collector to
collect unreferenced data?

Ans. We may call the garbage
collector to collect unreferenced data by executing the
System.GC.Collect() method.

Q42. How can we set the
Focus on a control in ASP.NET?

Ans. txtBox123.Focus();
OR Page.SetFocus(NameOfControl);

Q43. What are
Partial Classes in Asp.Net 2.0?

Ans. In .NET 2.0, a
class definition may be split into multiple physical files but
partial classes do not make any difference to the compiler as
during compile time, the compiler groups all the partial
classes and treats them as a single class.

Q44. How
to set the default button on a Web Form?

Ans.
<asp:form id="form1" runat="server"
defaultbutton="btnGo"/>

Q45.Can we force the
garbage collector to run?

Ans. Yes, using the
System.GC.Collect(), the garbage collector is forced to run in
case required to do so.

Q46. What is Boxing and
Unboxing?

Ans. Boxing is the process where any value
type can be implicitly converted to a reference type object
while Unboxing is the opposite of boxing process where the
reference type is converted to a value type.

Q47.
What is Code Access security? What is CAS in .NET?

Ans.
CAS is the feature of the .NET security model that determines
whether an application or a piece of code is permitted to run
and decide the resources it can use while running.


Q48. What is Multi-tasking?
Ans. It is a
feature of operating systems through which multiple programs
may run on the operating system at the same time, just like a
scenario where a Notepad, a Calculator and the Control Panel
are open at the same time.

Q49. What is
Multi-threading?

Ans. When an application performs
different tasks at the same time, the application is said to
exhibit multithreading as several threads of a process are
running.2

Q50. What is a Thread?
Ans. A
thread is an activity started by a process and its the basic
unit to which an operating system allocates processor
resources.

Q51. What does AddressOf in VB.NET
operator do?

Ans. The AddressOf operator is used in
VB.NET to create a delegate object to a method in order to
point to it.

Q52. How to refer to the current
thread of a method in .NET?

Ans. In order to refer to
the current thread in .NET, the Thread.CurrentThread method
can be used. It is a public static property.

Q53.
How to pause the execution of a thread in .NET?

Ans.
The thread execution can be paused by invoking the
Thread.Sleep(IntegerValue) method where IntegerValue is an
integer that determines the milliseconds time frame for which
the thread in context has to sleep.

Q54. How can we
force a thread to sleep for an infinite period?

Ans.
Call the Thread.Interupt() method.

Q55. What is
Suspend and Resume in .NET Threading?

Ans. Just like a
song may be paused and played using a music player, a thread
may be paused using Thread.Suspend method and may be started
again using the Thread.Resume method. Note that sleep method
immediately forces the thread to sleep whereas the suspend
method waits for the thread to be in a persistable position
before pausing its activity.

Q56. How can we
prevent a deadlock in .Net threading?

Ans. Using
methods like Monitoring, Interlocked classes, Wait handles,
Event raising from between threads, using the ThreadState
property.

Q57. What is Ajax?
Ans.
Asyncronous Javascript and XML - Ajax is a combination of
client side technologies that sets up asynchronous
communication between the user interface and the web server so
that partial page rendering occur instead of complete page
postbacks.

Q58. What is XmlHttpRequest in
Ajax?

Ans. It is an object in Javascript that allows
the browser to communicate to a web server asynchronously
without making a postback.

Q59. What are the
different modes of storing an ASP.NET session?

Ans.
InProc (the session state is stored in the memory space of the
Aspnet_wp.exe process but the session information is lost when
IIS reboots), StateServer (the Session state is serialized and
stored in a separate process call Viewstate is an object in
.NET that automatically persists control setting values across
the multiple requests for the same page and it is internally
maintained as a hidden field on the web page though its hashed
for security reasons.

Q60. What is a delegate in
.NET?

Ans. A delegate in .NET is a class that can have
a reference to a method, and this class has a signature that
can refer only those methods that have a signature which
complies with the class.

Q61. Is a delegate a type-safe functions
pointer?

Ans. Yes

Q62. What is the return
type of an event in .NET?

Ans. There is No return type
of an event in .NET.

Q63. Is it possible to specify
an access specifier to an event in .NET?

Ans. Yes,
though they are public by default.

Q64. Is it
possible to create a shared event in .NET?

Ans. Yes,
but shared events may only be raised by shared
methods.

Q65. How to prevent overriding of a class
in .NET?

Ans. Use the keyword NotOverridable in VB.NET
and sealed in C#.

Q66. How to prevent inheritance of
a class in .NET?

Ans. Use the keyword NotInheritable in
VB.NET and sealed in C#.

Q67. What is the purpose of
the MustInherit keyword in VB.NET?

Ans. MustInherit
keyword in VB.NET is used to create an abstract
class.

Q68. What is the access modifier of a member
function of in an Interface created in .NET?

Ans. It is
always public, we cant use any other modifier other than the
public modifier for the member functions of an
Interface.

Q69. What does the virtual keyword in C#
mean?

Ans. The virtual keyword signifies that the
method and property may be overridden.

Q70. How to
create a new unique ID for a control?

Ans.
ControlName.ID = "ControlName" + Guid.NewGuid().ToString();
//Make use of the Guid class

Q71A. What is a
HashTable in .NET?

Ans. A Hashtable is an object that
implements the IDictionary interface, and can be used to store
key value pairs. The key may be used as the index to access
the values for that index.

Q71B. What is an
ArrayList in .NET?

Ans. Arraylist object is used to
store a list of values in the form of a list, such that the
size of the arraylist can be increased and decreased
dynamically, and moreover, it may hold items of different
types. Items in an arraylist may be accessed using an
index.

Q72. What is the value of the first item in
an Enum? 0 or 1?

Ans. 0

Q73. Can we achieve
operator overloading in VB.NET?

Ans. Yes, it is
supported in the .NET 2.0 version, the "operator" keyword is
used.

Q74. What is the use of Finalize method in
.NET?

Ans. .NET Garbage collector performs all the
clean up activity of the managed objects, and so the finalize
method is usually used to free up the unmanaged objects like
File objects, Windows API objects, Database connection
objects, COM objects etc.

Q75. How do you save all
the data in a dataset in .NET?

Ans. Use the
AcceptChanges method which commits all the changes made to the
dataset since last time Acceptchanges was
performed.

Q76. Is there a way to suppress the
finalize process inside the garbage collector forcibly in
.NET?

Ans. Use the GC.SuppressFinalize()
method.

Q77. What is the use of the dispose() method
in .NET?

Ans. The Dispose method in .NET belongs to
IDisposable interface and it is best used to release unmanaged
objects like File objects, Windows API objects, Database
connection objects, COM objects etc from the memory. Its
performance is better than the finalize()
method.

Q78. Is it possible to have have different
access modifiers on the get and set methods of a property in
.NET?

Ans. No we can not have different modifiers of a
common property, which means that if the access modifier of a
property's get method is protected, and it must be protected
for the set method as well.

Q79. In .NET, is it
possible for two catch blocks to be executed in one
go?

Ans. This is NOT possible because once the correct
catch block is executed then the code flow goes to the finally
block.

Q80. Is there any difference between
System.String and System.StringBuilder classes?

Ans.
System.String is immutable by nature whereas
System.StringBuilder can have a mutable string in which plenty
of processes may be performed.

Q81. What technique is used to figure out that
the page request is a postback?

Ans. The IsPostBack
property of the page object may be used to check whether the
page request is a postback or not. IsPostBack property is of
the type Boolean.

Q82. Which event of the ASP.NET
page life cycle completely loads all the controls on the web
page?

Ans. The Page_load event of the ASP.NET page life
cycle assures that all controls are completely loaded. Even
though the controls are also accessible in Page_Init event but
here, the viewstate is incomplete.

Q83. How is
ViewState information persisted across postbacks in an ASP.NET
webpage?

Ans. Using HTML Hidden Fields, ASP.NET creates
a hidden field with an ID="__VIEWSTATE" and the value of the
page's viewstate is encoded (hashed) for
security.

Q84. What is the ValidationSummary control
in ASP.NET used for?

Ans. The ValidationSummary control
in ASP.NET displays summary of all the current validation
errors.

Q85. What is AutoPostBack feature in
ASP.NET?

Ans. In case it is required for a server side
control to postback when any of its event is triggered, then
the AutoPostBack property of this control is set to
true.

Q86. What is the difference between Web.config
and Machine.Config in .NET?

Ans. Web.config file is
used to make the settings to a web application, whereas
Machine.config file is used to make settings to all ASP.NET
applications on a server(the server machine).

Q87.
What is the difference between a session object and an
application object?

Ans. A session object can persist
information between HTTP requests for a particular user,
whereas an application object can be used globally for all the
users.

Q88. Which control has a faster performance,
Repeater or Datalist?

Ans. Repeater.

Q89.
Which control has a faster performance, Datagrid or
Datalist?

Ans. Datalist.

Q90. How to we add
customized columns in a Gridview in ASP.NET?

Ans. Make
use of the TemplateField column.

Q91. Is it possible
to stop the clientside validation of an entire
page?

Ans. Set Page.Validate = false;

Q92. Is
it possible to disable client side script in
validators?

Ans. Yes. simply EnableClientScript =
false.

Q93. How do we enable tracing in .NET
applications?

Ans. <%@ Page Trace="true"
%>

Q94. How to kill a user session in
ASP.NET?

Ans. Use the Session.abandon()
method.

Q95. Is it possible to perform forms
authentication with cookies disabled on a browser?

Ans.
Yes, it is possible.

Q96. What are the steps to use
a checkbox in a gridview?

Ans.
<ItemTemplate>
<asp:CheckBox id="CheckBox1"
runat="server" AutoPostBack="True"

OnCheckedChanged="Check_Clicked"></asp:CheckBox>
</ItemTemplate>

Q97.
What are design patterns in .NET?

Ans. A Design pattern
is a repeatitive solution to a repeatitive problem in the
design of a software architecture.

Q98. What is
difference between dataset and datareader in
ADO.NET?

Ans. A DataReader provides a forward-only and
read-only access to data, while the DataSet object can carry
more than one table and at the same time hold the
relationships between the tables. Also note that a DataReader
is used in a connected architecture whereas a Dataset is used
in a disconnected architecture.

Q99. Can connection
strings be stored in web.config?

Ans. Yes, in fact this
is the best place to store the connection string information.


Q100. Whats the difference between web.config and
app.config?

Ans. Web.config is used for web based
asp.net applications whereas app.config is used for windows
based applications.