Page Caching In ASP.NET

public static string GetStockXMLFromCache()
    {
        // Get reference to calling page
        Page page = (Page)HttpContext.Current.CurrentHandler;
        string cacheKey = "StockXML";
        string xml = "";

        if (page.Cache[cacheKey] != null)
        {
            // Return the cached version
            return (string)page.Cache[cacheKey];
        }
        else
        {
            // Fill cache
            // Get file path to stock xml
            string xmlPath = HttpContext.Current.Server.MapPath("/path/to/stock.xml");

            // XML Reader
            XmlTextReader xtr = new XmlTextReader(xmlPath);
            XmlDocument xmlDoc = new XmlDocument();
            xmlDoc.Load(xtr);
            // Close reader
            xtr.Close();
            xml = xmlDoc.OuterXml;


            // Create cache dependency based on the xml file
            CacheDependency dependency = new CacheDependency(xmlPath);
            // Add xml to cache with dependency
            page.Cache.Insert(cacheKey, xml, dependency);
        }

        return xml;
    }

Advertisements

How to import/export SQL tables, functions and stored procs with SQL Management Studio 2005

  • In Microsoft SQL Server Management Studio Express, expand the databases.
  • Right-Click on the database containing objects you want to copy to another database
  • Click on Tasks, then Generate Scripts… This will open up the Script Wizard, which is pretty much self-explanatory:
    • Select the database (which should be pre-selected for you),
    • Select Options (first time around you might just accept the default selections),
    • Choose the Object Types you want to script (Stored Procedures, User Defined Functions, etc),
    • Select the specific objects to be scripted,
    • and finally specify where to output the script (choose Script to new Query Window for convenience).
  • Once completed, return to the Query Window with the scripted objects.  Change the USE directive (the first line) to point to the destination database (e.g., USE [Northwind]), and execute the script.

source

Extract Description From Enum

C#

using System.ComponentModel;
using System.Reflection;

...
..
.

            //  instantiate List of enum and add to it
            List<InvestorEmailAlertType> subscriptions = new List<InvestorEmailAlertType>();
            subscriptions.Add(InvestorEmailAlertType.AllCorporateNewsReleases);
            subscriptions.Add(InvestorEmailAlertType.FinancialNewsReleasesOnly);

          // Create another List of type string to hold Enum Descriptions
            List<string> subscriptionDesc = new List<string>();

            foreach (InvestorEmailAlertType subscriptionChoice in subscriptions)
            {
                subscriptionDesc.Add(GetEnumDescription(subscriptionChoice));
            }


    public static string GetEnumDescription(Enum value)
    {
        FieldInfo fi = value.GetType().GetField(value.ToString());
        DescriptionAttribute[] attributes =
              (DescriptionAttribute[])fi.GetCustomAttributes(
              typeof(DescriptionAttribute), false);
        return (attributes.Length > 0) ? attributes[0].Description : value.ToString();
    }

InvestorEmailAlertType Enum

using System;
using System.ComponentModel;


public enum InvestorEmailAlertType
{
    [Description("All corporate news releases")]
    AllCorporateNewsReleases,

    [Description("Financial news releases only")]
    FinancialNewsReleasesOnly,

    [Description("Environmental news releases only")]
    EnvironmentalNewsReleasesOnly,

    [Description("Operations news releases only")]
    OperationsNewsReleasesOnly,

    [Description("All regional utility news releases")]
    AllRegionalUtilityNewsReleases,

    [Description("Investor presentation updates")]
    InvestorPresentationUpdates,

    [Description("Investor calendar updates")]
    InvestorCalendarUpdates,

    [Description("Financial webcast alerts")]
    FinancialWebcastAlerts,

    [Description("All SEC Filings")]
    AllSECFilings,

    [Description("Quarterly and Annual Reports")]
    QuarterlyAndAnnualReports,

    [Description("Insider Transactions")]
    InsiderTransactions,

    [Description("Quote By Email")]
    QuoteByEmail

}

Bind ASP.NET Repeater to List of Enum’s

C#

            //  instantiate List of enum and add to it
            List<InvestorEmailAlertType> subscriptions = new List<InvestorEmailAlertType>();
            subscriptions.Add(InvestorEmailAlertType.AllCorporateNewsReleases);
            subscriptions.Add(InvestorEmailAlertType.FinancialNewsReleasesOnly);

            // Bind list to repeater
            RepeaterSubscriptions.DataSource = subscriptions;
            RepeaterSubscriptions.DataBind();

ASP.NET

            <asp:Repeater ID="RepeaterSubscriptions" runat="server">
                <ItemTemplate>
                    <ul>
                        <li>
                            <%# Container.DataItem %>
                        </li>
                    </ul>
                </ItemTemplate>
            </asp:Repeater>     

Uncheck and Disable CheckBox Using JavaScript and ASP.NET CheckBox Controls

Register JavaScript onclick events to ASP.NET CheckBox controls:

protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);

        // Add client-side onclick to handle disabling of child checkboxes
        cbAllCorporateNewsReleases.Attributes.Add("onclick", "DisableCheckbox('AllCorporateNewsReleases')");
        cbAllSECFilings.Attributes.Add("onclick", "DisableCheckbox('AllSECFilings')");

    }

JavaScript code:



    <script type="text/javascript" language="javascript">
        function DisableCheckbox(checkBoxItem) {

            switch (checkBoxItem) {
                case "AllCorporateNewsReleases":
                    // Disable and Uncheck Financial news releases only checkbox
                    document.getElementById("<%= cbFinancialNewsReleasesOnly.ClientID %>").disabled = document.getElementById("<%= cbAllCorporateNewsReleases.ClientID %>").checked;
                    document.getElementById("<%= cbFinancialNewsReleasesOnly.ClientID %>").checked = false;

                    // Disable and Uncheck Environmental news releases only checkbox
                    document.getElementById("<%= cbEnvironmentalNewsReleasesOnly.ClientID %>").disabled = document.getElementById("<%= cbAllCorporateNewsReleases.ClientID %>").checked;
                    document.getElementById("<%= cbEnvironmentalNewsReleasesOnly.ClientID %>").checked = false;

                    // Disable and Uncheck Operations news releases only checkbox
                    document.getElementById("<%= cbOperationsNewsReleasesOnly.ClientID %>").disabled = document.getElementById("<%= cbAllCorporateNewsReleases.ClientID %>").checked;
                    document.getElementById("<%= cbOperationsNewsReleasesOnly.ClientID %>").checked = false;

                    break;

                case "AllSECFilings":
                    // Disable and Uncheck Quarterly and Annual Reports checkbox
                    document.getElementById("<%= cbQuarterlyAndAnnualReports.ClientID %>").disabled = document.getElementById("<%= cbAllSECFilings.ClientID %>").checked;
                    document.getElementById("<%= cbQuarterlyAndAnnualReports.ClientID %>").checked = false;

                    // Disable and Uncheck Insider Transactions checkbox
                    document.getElementById("<%= cbInsiderTransactions.ClientID %>").disabled = document.getElementById("<%= cbAllSECFilings.ClientID %>").checked;
                    document.getElementById("<%= cbInsiderTransactions.ClientID %>").checked = false;


                    break;
            }


        }
    </script>


ASP.NET CheckBox controls:

  <div id="NewsReleases">
            <img class="sub" alt="News Releases" src="images/sub_NewsReleases.gif" />
            <table border="0">
                <tr>
                    <td>
                        <asp:CheckBox ID="cbAllCorporateNewsReleases" runat="server" Text="All corporate news releases" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="cbFinancialNewsReleasesOnly" runat="server" Text="Financial news releases only"
                            CssClass="indentCheckbox" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="cbEnvironmentalNewsReleasesOnly" runat="server" Text="Environmental news releases only"
                            CssClass="indentCheckbox" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="cbOperationsNewsReleasesOnly" runat="server" Text="Operations news releases only"
                            CssClass="indentCheckbox" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="cbAllRegionalUtilityNewsReleases" runat="server" Text="All regional utility news releases" />
                    </td>
                </tr>
            </table>
            
        </div>
        <div id="Events">
            <img class="sub" alt="Events" src="images/sub_Events.gif" />
            <table border="0">
                <tr>
                    <td>
                        <asp:CheckBox ID="cbInvestorPresentationUpdates" runat="server" Text="Investor presentation updates" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="cbInvestorCalendarUpdates" runat="server" Text="Investor calendar updates" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="cbFinancialWebcastAlerts" runat="server" Text="Financial webcast alerts" />
                    </td>
                </tr>
            </table>
        </div>
        <div id="SECAlerts">
            <img class="sub" alt="SEC Filings" src="images/sub_SECFilings.gif" />
            <table border="0">
                <tr>
                    <td>
                        <asp:CheckBox ID="cbAllSECFilings" runat="server" Text="All SEC Filings" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="cbQuarterlyAndAnnualReports" runat="server" Text="Quarterly and Annual Reports"
                            CssClass="indentCheckbox" />
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:CheckBox ID="cbInsiderTransactions" runat="server" Text="Insider Transactions"
                            CssClass="indentCheckbox" />
                    </td>
                </tr>
            </table>
        </div>
        <div id="StockAlerts">
            <img class="sub" alt="Stock Information" src="images/sub_StockInformation.gif" />
            <table border="0">
                <tr>
                    <td>
                        <asp:CheckBox ID="cbQuoteByEmail" runat="server" Text="Quote By Email" />
                    </td>
                </tr>
            </table>
        </div>