Showing posts from 2016

How to access Session in javascript

Introduction In this article we learn about how we can access ASP.NET server side session variable or data in client side JavaScript. I have requirement for current user session variable in client side to perform some action based on user and its role. Here are method or way to interact session variable in client side or in JavaScript. 1. Directly access session variable with mix code( Server side) as per the below code. //First way to access session console.log("UserId:" + '<%=Session["UserId"] %>'); console.log("UserRole:" + '<%=Session["UserRole"] %>'); 2. Fetch session value from HiddenField To fetch session value from hidden field first we have to set session data in server side and then we can access stored hidden value data in client side javascript. //Set session value to hidden field for access this value in jquery protected void setSessionToHiddenValue() {

Asp.Net Utility Functions

Introduction This article contains most useful utility function for Asp.Net WebForm as well as Asp.Net MVC project. All this method is collected from Internet sources like stackoverflow so it will be useful to many developer to find all useful method at one place. See listed below most useful functions 1. Replace all special character in input string with '-' character This method replace special characters using Regex function public static string ReplaceSpecialChar(string input) { Regex rgx = new Regex("[^a-zA-Z0-9]"); input = rgx.Replace(input, "-"); return input; } 2. Remove all special characters from string This method remove all special characters and prepare new string which contains alpha numeric character along with underscore and space. public static string RemoveSpecialCharacters(string str) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < str.Le

Exception LINQ to Entities does not recognize the method ToString

Introduction This is most common exception occurs while we working with entity framework and converting data inside IQueryable result for filtering. Description Mainly full exception message as “ LINQ to Entities does not recognize the method ' System.String ToString() ' method, and this method cannot be translated into a store expression.” var result=dc.Tests.Where(i=>i.status==status.ToString()).FirstOrDefault(); This exception mainly occurs, when we query SQL database using entity framework. The problem is that you are calling ToString in a LINQ to Entities query (IQueryable to IEnumrable). That means the parser is trying to convert the ToString call into its equivalent SQL (which isn't possible...hence the exception). To solve this problem there is different solution. Solution 1:   All you have to do is move the ToString call to a separate line. String userStatus=status.ToString(); var result=dc.Tests.Where(i=>i.status== userStatus).FirstOrDefau

Getting started with data visualization using D3js

Introduction As per   D3 allows you to bind arbitrary data to a Document Object Model (DOM), and then apply data-driven transformations to the document. For example, you can use D3 to generate an HTML table from an array of numbers. Or, use the same data to create an interactive SVG bar chart with smooth transitions and interaction. Description Here we learn basic usage of D3js and then moved to different type of visualization chart. 1. How Selections works Modifying documents using the W3C DOM API is tedious For example, to change the text color of paragraph elements: var paragraphs = document.getElementsByTagName("p"); for (var i = 0; i < paragraphs.length; i++) { var paragraph = paragraphs.item(i);"color", "white", null); } D3 uses new W3C Selectors API and supported natively by modern browsers. Elements may be selected using a variety of predicates, including containment, a

Selected as Article Of The Day in MSFT

  Selected As Article Of The Day in Microsoft ASP.NET Community My Article on JUICE UI library got selected as Article Of The Day for 07-Feb-2016 on Asp.Net Forum.  Article Of  The Day Thank you Asp.Net community for recognizing my article as Article Of The Day.