Gautam Buddha Temple Varanasi,Varanasi - Buddhist Pilgrimage

Monday, August 11, 2014

Read a single node from xml (C# String) in C#/.net

 I want to pass the ID as a input parameter of the given xml that will search the XML document for that value within the <id> node.   
 Once ID found ,I want to find the next node and return it's name as a string.  
 Given xml as folloing:  
   <Add>Navi Mumbai</Add>  
 This Linq to xml query will return IEnumerbale<string> of value elements, which matched your id. You need to sure ID should be  
 unquine in given xml.  
 string value = doc.Descendants("Setting")  
            .Where(v => (string)v.Element("ID") == Id)  
            .Select(v => (string)v.Element("Name"))  

Tuesday, January 21, 2014

Caching in ASP.NET ?

Caching is technique of persisting the data in memory for immediate access to requesting program calls.Caching is feature to improve application performance of web application.There are three types of caching available in

Output Caching :
This is at the page level and one of the easiest way of caching a page.
 <%@ OutputCache Duration="60" VaryByParam="none" %>  

VaryByParam attribute makes sure that there is a single cached page available for this duration specified.

Fragment Caching :
Some times we might want to cache just portions of a page.
Eg.Suppose we want to cache header of our page which will have the some content for all users.There might be some Text/Images in the header which might change everyday.In this case we will cache this header for a duration of a day. The solution will be put header in a user control and then cached the user control as output caching.As below
 <% OutputCache Duration="10" VaryByParam="None"%>  

This technique is known as fragment Cachng.

Data Caching :
ASP.NET also support caching of data as objects.We can store objects in memory and use then across various pages in our application.This feature is impemented using the cache class.The cache class has life time equivalent to that of the applicaton objects can be stored as name pairs in the cache.
 Cache["name"] ="santosh";  
 if(Cache["name"] != null)  
    lbl.text = Cache["name"].ToString();  

Types of session management in ASP.NET

Session object is used to store state specific information per user basis.Session object can be configured 3 ways based on availability and scalability of web application.

In Process Mode:
This is default mode and useful for small application which is hosted on single server.
-Fastest mode.
-Simple configuration.
-Session data will be lost if worker process or application domain recycle.
-Not ideal for web garden and web form.

Out-of-process session mode(State server mode):
This mode is useful for highly available and scalable applications.Session state is stored in a process called aspnet_state.exe that runs as a windows service which listens on TCP port 42424 by default.
-Supports web farm and web garden configuration.
-Session data is persisted across application domain recycles.This is achieved by using separate worker process for maintaining state.
-Out-of-process mode provides slower access compared to in process.
-Requires serializing data.

Sql-Backed Session State: Session can also be stored in sql server database.Storing session in DB offers resilience that can serve session to a large web farm that persists across IIS restarts.SQL based session state is configured with aspnet_regsql.exe.
-Supports web farm and web garden configuration.
-Session State is persisted across application domain recycles and even IIS restarts.
-Required serialized of objects.

Which control would you see if you need to make sure the values in two different controls matched ?

Compare Validator

Monday, January 20, 2014

Difference between Server.Transfer and Response.Redirect

Server.Transfer transfer page processing from one page to another page directory to the next page without making a round trip back to the client browser.This provides a faster response with a little less overhead on the server.Server.Transfer does not update the url.

Response.Redirect is used to redirect the user browser to another page or website.This performs a tripback to the client where client browser redirected to the new page.The user browser url is updated to reflect the new address.

What are the differences between user control and server control

User Control
1.Re-usability in web pages
2.Can not add to toolbox
3.Drag and drop from solution explorer to page
3.You can register user control to .aspx page by Register tag
4.This is good for static layout
5.Easier to create
6.Can not compiled into DLL
7.Can not use in other web application.

Custom Control
1.It can be compile into DLL.
2.Re-usability of control
3.We can Add to toolbox
4.We can drag and drop from toolbox
5.Good for dynamic layout.
6.We can register user control to .aspx by registering
7.A single copy of control can be used in any other web application.

How to fetch ricord between 3 and 15 only, if a dataset contains 100 rows

 SqlDataAdapter da = new SqlDataAdapter("usp_GetData",con);  
 DataSet ds1 = new DataSet();  
 int rowcount = ds1.Table[0].Rows.Count;  
 if(rowcount >=15)  
      for(int i=3;i<=15;i++)  
           lbl.Text = Convert.ToSting(ds1.Table[0].Row[i].ToString());  

Sunday, January 19, 2014

What is Viewstate ? What are the advantages and disadvantages of it view state?

View state is used to retain the state of the server side objects between post backs.

Advantages :
-Simple for page level data
-Can be set at the control level.

Disadvantages :
-Overhead in encoding view state values
-Makes a page heavy

What is diffgram

The Diffgram is one of the two XML format that you can use to render Dataset object content to XML.For example if you are reading database data to on XML file to be sent to a web service.

Monday, January 13, 2014

Some basic linq to object query example.

Here code sample uses where clause to find all elements of an array which is less than 4.
  public void Sample1()   
     int[] num = { 8, 2, 4, 1, 5, 0, 2, 6, 7, 9 };   
     var objNum = from n in num   
                           where n < 4   
                           select n;   
     Console.WriteLine("Numbers < 4:");   
     foreach (var n in objNum)   


What is LINQ?
LINQ stand for Language-Integrated Query. It is new feature introduce in Visual Studio 2008. It has powerful query capabilities to querying on any source of data, data could be sql server database, oracle, collection of objects or xml files. Visual Studio includes LINQ provider assemblies that enable to querying with as given three area.
1.LINQ to Object

Wednesday, January 1, 2014

What is Post Back ?

Postback is the process of by which the browser sends information back to the server so that server can handle the event.The server executes the code sends the resulting HTML back to the browser again.Postback occurs only with web forms that have the runat="server" attribute.

Difference between Exe and DLL

An exe can run independently where as dll will run within an exe.DLL is an in process file and exe is out process file.

Difference between DataReader and DataSet

-DataSet can represent an entire relational database in memory,completely with table relation and views.
-DataSet is a disconnected architecture while DataReader has live connection while reading data.
-If we want to Cache data and want to pass in different layer DataSet is the best thing to choose.
-DataSet support XML.
-When we need to access data from more than one table DataSet is the best choice.
-If we need to move back while reading records DataReader does not support.
-If you want to quickly read and display record on page DataReader is good choice to use.

What does WSDL stand for ?

Web Service Description Language

What method do you use to explicitly kill a user’s session ?


What base class do all web forms inherit from ?

The Page class

What property must you set, and what method must you call in your code, in order to bind the data from some data source to the repeater control ?

We must set the DataSource property and call the DataBind() method

How can you provide an alternating color scheme in a Repeater control ?


Which template must you provide, in order to display data in a Repeater control?


Can you edit data in Repeater control ?

No, Repeater control can reads the information from its data source.We can not edit with Repeater control.

Which methos do you invoke on the DataAdapter control to load your generated dataset with data?

Fill() method.

Bindings in WCF

Below are different bindings available in WCF.

Difference Between

Difference between Component and Services

A component is a piece of compiled code that can be assembled with other components to build applications.
A service is implemented by one or more component, and is a higher level aggregation.

Service Oriented Architecture (SOA)

Service Oriented Architecture(SOA) is a collection of well defined services. A service is an autonomous system that accepts one or more requests and returns one or more responses as a set of published and well defined interfaces.
Unlike traditional web service, tightly couples architectures SOA implements a set of loosely coupled services that collectively achieve the desired results.
In addition since the underlying implementation details are hidden from the consumer, changes to the implementation won’t affect the service, as long as the contract does not change. This allows system based on SOA to respond more quickly and cost effectively for business.


WCF is the latest service oriented technology Interoperability is the fundamental characteristics of WCF.Windows Communication Foundation is an SDK for building, configuring and deploying network-distributed services.WCF provides a runtime environment for services, enabling you to expose CLR types as services, and to consume other services as CLR types.
WCF is the first programming model built from the ground upto provides explicit service oriented application development and future ready business orientation. Service orientation is not a technology but a design concept.
Service orientation uses the best practices for building distributed application.

Features in WCF :
1.Develper productivity
2.Attribute based development
3.Coexisting with existing technology
4.Hosting services
5.integration with existing technology
6.One service,multiple end points
7.Integration technologies.

Name two properties common in every validation control

ControlToValidate and ErrorMessage

What does the EnableViewState property do ?

EnableViewState stores the current state of the page and the objects in it like text,button,table etc.So this helps not loosing the state between client and server.It makes slow rendering on the browser so you should enable it only if required.