How To Compare 2 Lists Determining If A Property Has Changed, Ignoring Order

In the list you want to perform the comparison against, override Equals

    public class AlertSubscriptionOption
  /// <summary>
        /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
            // Check for null values and compare run-time types.
            if (obj == null || GetType() != obj.GetType())
                return false;

            AlertSubscriptionOption p = (AlertSubscriptionOption)obj;
            return this.SubType == p.SubType;

Now, to compare the 2 lists, perform the following

     bool subscriptionEmailDifferent = false;
    subscriptionEmailDifferent = (newSubscriptionEmailOptions.Count > 0 || oldSubscriptionEmailOptions.Count > 0) &&
                                          !newSubscriptionEmailOptions.OrderBy(x => x.SubType).ToList().SequenceEqual(oldSubscriptionEmailOptions.OrderBy(x => x.SubType).ToList());


Call ASP.Net Page Method using jQuery AJAX Example

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

    public static string GetCurrentTime(string name)
        return "Hello " + name + Environment.NewLine + "The Current Time is: "
            + DateTime.Now.ToString();


<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <script src="Scripts/jquery-2.1.3.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            function ShowCurrentTime() {
                    type: "POST",
                    url: "Default.aspx/GetCurrentTime",
                    data: '{name: "' + $("#<%=txtUserName.ClientID%>")[0].value + '" }',
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     success: OnSuccess,
                     failure: function (response) {
             function OnSuccess(response) {
                 $("#DivShowAfterClick").append("<p>" + response.d + "</p>");

            Your Name :
            <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
            <input id="btnGetTime" type="button" value="Show Current Time"
                onclick="ShowCurrentTime()" />

        <div id="DivShowAfterClick" runat="server">This should be invisible until button clicked.</div>



How To Easily Preserve State Of DIV (Hide/Show) Between Post-backs In ASP.NET with JavaScript

                          <p>Already have an online account? <a href="#" id="aLoginForStreamlined">Log in for a streamlined experience</a>.</p>

<div id="DivLoginForm" style="display: none">
                                       Content To Hide/Show Here!
 <asp:HiddenField ID="hdnLoginFormState" runat="Server" Value="0" />
                        // Retain Login Form expansion/contraction state between postbacks
                        $(document).ready(function () {
                            var hdnState = $('#<%=hdnLoginFormState.ClientID %>').val();
                             if (hdnState == "0") {
                             else {

                             $('a#aLoginForStreamlined').click(function () {

                                 var oldValue = $('#<%=hdnLoginFormState.ClientID %>').val();
                                 var newValue = (oldValue == 0) ? "1" : "0";
                                 $('#<%=hdnLoginFormState.ClientID %>').val(newValue);
                                 return false;



How To Easily Add Log4Net To Your .NET Project

  1. Download Log4Net binaries –>
  2. Add Reference to Log4Net.dll in your project
  3. Create new “Logs” folder and ensure Web App/Site has Write privileges to this directory
  4. Add the following to Global.asmx
        /// &lt;summary&gt;
        /// Gets the application log4net log instance.
        /// &lt;/summary&gt;
        /// &lt;value&gt;The log.&lt;/value&gt;
        public ILog log
            get { return LogManager.GetLogger(&quot;AppLogger&quot;); }
        void Application_Start(object sender, EventArgs e) 
            // Code that runs on application startup
  5. Add Log4Net config section and declaration into web.config/app.config
    <?xml version="1.0" encoding="utf-8" ?>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
        <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
          <file value="Logs/application.log"/>
          <appendToFile value="true"/>
          <rollingStyle value="Composite"/>
          <datePattern value="yyyyMMdd"/>
          <maxSizeRollBackups value="10"/>
          <maximumFileSize value="5MB"/>
          <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%n DATE: %date{MM/dd/yyyy HH:mm:ss} %n THREAD: [%thread] %n LEVEL: %-5level %n USER ID: %identity %n CLASS: %type{1} %n METHOD: %M %n LOCATION: %location %n MESSAGE: %message %n "/>
          <level value="DEBUG"/>
          <appender-ref ref="LogFileAppender"/>
  6. Add private static readonly property referencing ILog
      class Program
            /// &lt;summary&gt;
            /// Logging
            /// &lt;/summary&gt;
            //private readonly ILog Logger = DecisionLogManager.GetLogger(typeof(UC4Request));    
          private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  7. Call Error method to log error
                catch (Exception ex)
                    // Log to local log file
                    log.Error("Error", ex);
  8. You can also call other methods (Info) to output debug information
             log.Info(responseOutput +
                             Environment.NewLine +
                             Base.HelperFunctions.ObjectToString(keywordClientReply, DisplayMode.HTML)

ASP.NET Diagnostic Page to Dump ASP.NET and Environment Configuration

<%@ Page Language="C#" AutoEventWireup="true" Trace="true" TraceMode="SortByCategory" %>
<html xmlns="">
<head runat="server">
  <title>ASP.NET Diagnostic Page</title>
  <form id="form1" runat="server">
  <h2>Environment Variables</h2>
    var variables = Environment.GetEnvironmentVariables();
    foreach (DictionaryEntry entry in variables)

  Response.Filter = <%= Request.Filter.ToString() %>
  Request.ApplicationPath = <%= Request.ApplicationPath %>
  Request.PhysicalApplicationPath = <%= Request.PhysicalApplicationPath %>
  Request.PhysicalPath = <%= Request.PhysicalPath %>
  Request.UrlReferrer = <%= Request.UrlReferrer %>
  Request.UserLanguages = <%= string.Join(",", (Request.UserLanguages ?? new string[0])) %>


Navigate To Feature In Visual Studio 2012/2013

Visual Studio’s Navigate to feature allows you to find and navigate to a specific element in your solution. Once you press the Ctrl+, combination and start typing your query*, Visual Studio will display all found elements matching your query, regardless of their type and location. To navigate to a certain element, either select it with cursor keys and press Enter or double click the element.


Best Way To Clone An Object In .NET

using System;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;

/// <summary>
/// Reference Article
/// Provides a method for performing a deep copy of an object.
/// Binary Serialization is used to perform the copy.
/// </summary>
public static class ObjectCopier
    /// <summary>
    /// Perform a deep Copy of the object.
    /// </summary>
    /// <typeparam name="T">The type of object being copied.</typeparam>
    /// <param name="source">The object instance to copy.</param>
    /// <returns>The copied object.</returns>
    public static T Clone<T>(T source)
        if (!typeof(T).IsSerializable)
            throw new ArgumentException("The type must be serializable.", "source");

        // Don't serialize a null object, simply return the default for that object
        if (Object.ReferenceEquals(source, null))
            return default(T);

        IFormatter formatter = new BinaryFormatter();
        Stream stream = new MemoryStream();
        using (stream)
            formatter.Serialize(stream, source);
            stream.Seek(0, SeekOrigin.Begin);
            return (T)formatter.Deserialize(stream);

In case you prefer to use the new extension methods of C# 3.0, change the method to have the following signature

public static T Clone<T>(this T source)