New C# 6 Features

C# 6 makes coding even easier.  Watch how Michael Palermo guides the discussion by comparing previous approaches to common tasks with new ways introduced in version 6.  Features covered include auto property initializers, properties with expression bodies, methods with expression bodies, string interpolation, using static, and nameof operator.  Demo of code is presented in a simple ASP.NET…


A Better FindControl Method

For ASP.NET web forms developers, this is a handy extension method of the Control class that returns a strongly-typed control instance from a deep recursive search at any point in the control tree hierarchy: public static partial class ControlExtensions {     public static T FindControl<T>(this Control currentControl, string id) where T : Control  …


Get Embedded Resource as String

Here is a utility method for returning any embedded resource content as a string: public static partial class Tools { public static string GetEmbeddedContent(string resourceName) { Stream resourceStream = Assembly.GetAssembly(typeof(Tools)) .GetManifestResourceStream(resourceName); string content = null; using (StreamReader reader = new StreamReader(resourceStream)) { content = reader.ReadToEnd(); } return content; } }


AJAX Extension Methods

Although the ScriptManager has a property named IsInAsyncPostBack to determine an AJAX call, the control is scoped to the page it is contained in.  If writing code in a custom HTTP module, what if I need to know in the BeginRequest event whether the current request is AJAX or JSON? How nice it would be…