Posts

Showing posts from July, 2016

How to access Session in javascript

IntroductionIn 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(Asp.net 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() { Session.Add("…

Asp.Net Utility Functions

IntroductionThis 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 '-' characterThis 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 stringThis 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.Length; i++) { if…