Thursday, July 2, 2015

how to work with Entity Framework project

Steps to create entity frmawork project
1.Create a class library project for Context name YourProjectNameContext.
2.Right click the project and add new edmx.
3.Before creating edmx ensure that your Database is ready with proper relationship.
4.Open edmx file -> right click -> Add code generation Item -> select ADO.Net Self-tracking Entity Generator.
5.Add new Class library project for Entity named yourProjectNameEntities
6.Drag the .tt from Context project and drop it to Entity project.
7.Delete .tt files from Context project.
7.Reference - install entity framework,add refernce
8.Create your website/webapi project and add above created projects to here.

Santosh Singh

Thursday, June 4, 2015

Sticky menu on scroll in html5 and jquery

  Here, we will create a sticky menu bar in very simple way which is built only with CSS and jQuery.  
  1.Write this jquery code in top of your html page  
  <script type="text/javascript">  
     $(document).ready(function () {  
       var stickyTopPos = $('.navbar').offset().top;  
       var stickyNavbar = function () {  
         var scrollTop = $(window).scrollTop();  
         if (scrollTop > stickyTopPos) {  
         } else {  
       $(window).scroll(function () {  
 2.Add this stylesheet  
       position: fixed;  
       width: 100%;  
       left: 0;  
       top: 0;  
       z-index: 100;  
       border-top: 0;  
       background-color: #808080;  
 3.This is our menu  
  <div class="navbar">  
   <ul class="tabs" data-tab>  
     <li class="tab-title active"><a href="#panel1">Menu-1</a></li>  
     <li class="tab-title"><a href="#panel2">Menu-2</a></li>  
     <li class="tab-title"><a href="#panel3">Menu-3</a></li>  
     <li class="tab-title"><a href="#panel4">Menu-4</a></li>  
     <li class="tab-title"><a href="#panel5">Menu-5</a></li>  
     <li class="tab-title"><a href="#panel6">Menu-6</a></li>  
     <li class="tab-title"><a href="#panel7">Menu-7</a></li>     
   <div class="clear">  

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());