Posts

SetProperty and GetProperty with C# Reflection

SetProperty and GetProperty with C# Reflection   private object getProperty ( object containingObject, string propertyName ) { return containingObject. GetType ( ) . InvokeMember ( propertyName, BindingFlags. GetProperty , null , containingObject, null ) ; } private void setProperty ( object containingObject, string propertyName, object newValue ) { containingObject. GetType ( ) . InvokeMember ( propertyName, BindingFlags. SetProperty , null , containingObject, new object [ ] { newValue } ) ; }

Receive Json Web response in C#

Following code use to get Json Response in My object using (var twitpicResponse = (HttpWebResponse)request.GetResponse()) {         using (var reader = new StreamReader(twitpicResponse.GetResponseStream())) {             JavaScriptSerializer js = new JavaScriptSerializer();             var objText = reader.ReadToEnd();             MyObject myojb = (MyObject)js.Deserialize(objText,typeof(MyObject));         }     }

IIS 7 : To Execute function/code for very first request only

//In Following method call to FirstRequestInitialization is done every time beginRequest called for a Application. protected void Application_BeginRequest( Object source, EventArgs e) {     HttpApplication app = ( HttpApplication )source;     HttpContext context = app.Context;     // Attempt to peform first request initialization     FirstRequestInitialization .Initialize(context); } //Following Class will check the Flag(s_InitializedAlready) and according that it will execute Initializer function and check that request comes for first time or not. class FirstRequestInitialization {     private static bool s_InitializedAlready = false ;     private static Object s_lock = new Object ();     // Initialize only on the first request     public static void Initialize( HttpContext context)   ...

Jquery Ajax call, dont want to load from Cache.

To avoid loading data or content from cache when making Ajax call using Jquery, the following statement need to add in the document.ready block. $(document).ready( function () { $ . ajaxSetup ( { // Disable caching of AJAX responses     cache : false }); }); the above code will disable caching for Ajax response on the page.

Gridview to show header when Empty

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.showheaderwhenempty.aspx

Print Area of the Page

Following Jqury Plugin is used to print selected div or html to print http://plugins.jquery.com/project/PrintArea

Disable COPY PASTE and CUT

following link will help to disable copy paste and cut with jquery http://jquerybyexample.blogspot.com/2010/12/disable-cut-copy-and-paste-function-for.html