Homepage

Event Driven Developement using ASP.NET & C#

February 16th, 2008

Until recently I wasn’t entirely familiar with the concepts of Event Driven Programming, Event Bubbling, etc. Being a .NET developer I’ve been exposed to events and delegates but I never really understood the concept in its entirety. Somehow I had a hard time readily finding good sources online focusing on event driven programming especially using ASP.NET/C#. But I had to get myself more familiarized with the concept since I need to use a lot of that in my current project. So after doing some digging I found couple of good links which explain the concept quite well -

Hope that helps.

J | Programming | No comments Jump to the top of this page

10 ASP.NET Performance and Scalability Secrets

February 2nd, 2008

Very good article. Covers all the following topics:

  • ASP.NET Pipeline optimization
  • ASP.NET Process configuration optimization
  • Things you must do for ASP.NET before going live
  • Content Delivery Network
  • Caching AJAX calls on browser
  • Making best use of Browser Cache
  • On demand progressive UI loading for fast smooth experience
  • Optimize ASP.NET 2.0 Profile provider
  • How to query ASP.NET 2.0 Membership tables without bringing down the site
  • Prevent Denial of Service (DOS) attack

http://www.codeproject.com/KB/aspnet/10ASPNetPerformance.aspx

J | Programming, Web | No comments Jump to the top of this page

The dumbing-down of programming

January 21st, 2008

Very interesting article in Ekinoderm :

Doctors Robert Dewar and Edmond Schonberg (Professors Emeritus at NYU in Computer Science) recently penned a rather scathing paper about the sorry state of Computer Science education in the United States today. In it, we see the usual laments that Java is dumbing down Computer Science curricula and that the lack of emphasis on mathematics is making students completely uncompetitive in the global market. This is in an attempt to make CS “soft” and keep the numbers up in terms of number of people majoring and number of degrees granted. But this is what students want, apparently.When I got my B.S. (in 2003), I can remember students in my classes constantly grousing about how topics like Scheme or Finite State Automata were “useless” and we should spend our time doing “useful” things like learning how to use VB to make a database app or something. Or, God forbid, writing web apps in PHP.In one of my courses, the students actually got together and petitioned to have the course language changed from OCAML to Java (no kidding). And this was a Computer Languages class, where the entire purpose of the class was to write several interpreters to study different programming language constructs (such as closures or continuations). In case you aren’t familiar with it, OCAML is an ML-derivative which is designed for writing interpreters and compilers. Java is a general-purpose language which isn’t designed for anything specific, as near as I can tell. In this case, OCAML was unquestionably the better tool for the job, and yet, because students were uncomfortable having to learn a new language, and the professor was a bit weak-willed, we ended up having to deal with a monstrous interpreter written in Java. What was a few lines of OCAML became 20 or 30 files in Java (because each syntactic construct needs its own class).

These are the future software engineers of America, and they’re killing themselves. They’ve no one else to blame. As Dewar points out in his article, the adoption of Java is driven almost entirely by a desire to make programming “fun” and to alleviate students’ fears that they won’t learn anything “useful” from a course taught in an academic language like Scheme. The students are propped up by administrators who have a vested interest in graduating as many people as possible, regardless of how qualified they are. So, as is usual, you have the least qualified people making these decisions.

It’s like if you walked into a painting class, told everyone that learning to paint was too hard, and then gave everyone a camera and told them that photography was the same thing as painting, only a lot easier to do. No disrespect towards photographers intended.

From personal experience, I’d like to add that a lack of requirement for systems programming is making many CS grads almost completely useless in industry. I’ve interviewed candidates who literally fled from the room when I asked them to find a memory allocation problem in a “Hello World”-level C program. It’s apparently entirely possible at this point to have a Master’s degree (or possibly even a PhD) in Computer Science, and be unable to describe what memory management is or to know what a pointer is.

While I agree with the fundamental message of the article. I disagree when it boils down to the reality of it. I was one of the students who wanted to do “useful” things like learning how to program using C#/VB, ASP.NET, MS SQL 2005, etc. instead of learning how to write 10 line console applications in C++.

I would be more than happy to learn how to write finite state machines or some language complilers if it would help getting me a job after graduation. But it doesn’t! I’ve been through many interviews where all the employer cared about was what I could do for their company. Did I know all the tools and languages that they used?? They didn’t care if I knew the history of computer science, or how to write a complier in C. I’ve had many employers who have said this to me up-front. So I dont think its the students’ fault that they don’t want to learn the fundamentals. What they want to learn is driven by the market.

J | Career, Programming, Science & Tech. | No comments Jump to the top of this page

The veil is lifted

January 17th, 2008

Scott Guthrie announced today that they are finally releasing the source code to the .NET Framework libraries. So far you can now browse and debug the source code for the following .NET Framework libraries:

  • .NET Base Class Libraries (including System, System.CodeDom, System.Collections, System.ComponentModel, System.Diagnostics, System.Drawing, System.Globalization, System.IO, System.Net, System.Reflection, System.Runtime, System.Security, System.Text, System.Threading, etc).
  • ASP.NET (System.Web, System.Web.Extensions)
  • Windows Forms (System.Windows.Forms)
  • Windows Presentation Foundation (System.Windows)
  • ADO.NET and XML (System.Data and System.Xml)

…with more to come.

With in-built debugging support in VS 2008, this is really going to improve developers’ understaning of the .NET framework and lead them all to write better applications. Yet another reason to make the switch to VS 2008!

More from Scott Guthrie

J | Programming | No comments Jump to the top of this page

C# Coding Standards and Best Programming Practices

January 16th, 2008

I was reading a best practices document created by the DotNetSpider team which covered many aspects of programming in .NET. I was really impressed by it and I think its a very good reference document. So I’ve decided to make a series of posts where I’ll post sections of their document covering a specific topic.

J | Programming | 1 comment Jump to the top of this page

A Semi-Dynamic Sitemap Solution

January 12th, 2008

I was creating a website which had pages with multiple views. I wanted a fairly simple sitemap solution, without creating any custom sitemap provider, which could show the current view name in the breadcrumb trail like this -

Home >> Parent Page >> Current Page >> Current View 1
Home >> Parent Page >> Current Page >> Current View 2

So here’s what I did to achieve that -

MasterPage.Master:

<%@ Master Language=”C#” AutoEventWireup=”true” CodeFile=”MasterPage.master.cs” Inherits=”MasterPage” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head runat=”server”>
    <title>CMS ::</title>
</head>
<body>
    <form id=”form1″ runat=”server”>
        <div>
            <asp:SiteMapPath ID=”SiteMapPath1″ runat=”server” OnPreRender=”SiteMapPath1_PreRender” PathSeparator=” :  “ RenderCurrentNodeAsLink=”True”>
            </asp:SiteMapPath>
        </div>
        <div>
            <asp:ContentPlaceHolder ID=”ContentPlaceHolder1″ runat=”server”>
            </asp:ContentPlaceHolder>
        </div>
    </form>
</body>
</html>

MasterPage.master.cs:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class MasterPage : System.Web.UI.MasterPage
{
    private string _currentViewName = string.Empty;
    public string CurrentViewName
    {
        get { return _currentViewName; }
        set { _currentViewName = value; }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        SiteMap.SiteMapResolve += new SiteMapResolveEventHandler(SiteMap_SiteMapResolve);
    }
    protected void SiteMapPath1_PreRender(object sender, EventArgs e)
    {
        //If there is a current view name defined then add a child node to the breadcrumb trail.
        if (!string.IsNullOrEmpty(CurrentViewName))
        {
            SiteMapNodeItem sepItem = new SiteMapNodeItem(-1, SiteMapNodeItemType.PathSeparator);
            ITemplate sepTemplate = SiteMapPath1.PathSeparatorTemplate;
            if (sepTemplate == null)
            {
                Literal separator = new Literal();
                separator.Text = SiteMapPath1.PathSeparator;
                sepItem.Controls.Add(separator);
            }
            else
            {
                sepTemplate.InstantiateIn(sepItem);
            }
            sepItem.ApplyStyle(SiteMapPath1.PathSeparatorStyle);

            SiteMapNodeItem viewItem = new SiteMapNodeItem(-1, SiteMapNodeItemType.Current);
            Literal viewName = new Literal();
            viewName.Text = CurrentViewName;
            viewItem.Controls.Add(viewName);
            viewItem.ApplyStyle(SiteMapPath1.CurrentNodeStyle);

            SiteMapPath1.Controls.AddAt(-1, sepItem);
            SiteMapPath1.Controls.AddAt(-1, viewItem);
        }
        else //…if not then don’t show the current node as a link.
        {
            SiteMapPath mySMP = (SiteMapPath)sender;
            mySMP.RenderCurrentNodeAsLink = false;
            mySMP.DataBind();
        }
    }
    private SiteMapNode SiteMap_SiteMapResolve(Object sender, SiteMapResolveEventArgs e)
    {
        SiteMapNode currentNode = SiteMap.CurrentNode.Clone(true);         

        //If there is a current view defined then set the URLs in the breadcrumb trail 
        //so that they point to the correct view. For example:
        //Home (Home.aspx) > News (News.aspx?View=0) > Edit (News.aspx?View=1)
        if (!string.IsNullOrEmpty(CurrentViewName))
        {
            string currentRequest = e.Context.Request.UrlReferrer.PathAndQuery;

            if (currentNode != null)
                currentNode.Url = currentRequest;
        }

        return currentNode;
    }
}

Now you are all set. To put this code in action, just declare a curent view name like this in your pages wherever needed:

((MasterPage)this.Master).CurrentViewName = “News Listing”;

This solution was inspired by this blog post.

J | Programming | No comments Jump to the top of this page

How to extract URLs (href property) from HTML

January 5th, 2008

protected ArrayList getURL(string txtIn)
{
    ArrayList outURL = new ArrayList();
    Regex r = new Regex(“href\\s*=\\s*(?:(?:\\\”(?<url>[^\\\”]*)\\\”)|(?<url>[^\\s]* ))”);
    MatchCollection mc1 = r.Matches(txtIn);

    foreach (Match m1 in mc1)
    {
        foreach (Group g in m1.Groups)
        {
            outURL.Add(g.Value);
        }
    }

    return outURL;
}

J | Programming | 2 comments Jump to the top of this page

Workaround for Response.Redirect

January 5th, 2008

This is a workaround to do a redirect while using ASP.NET AJAX Framework. The traditional Response.Redirect method can not be used since it is not compatible with the .NET AJAX framework.

StringBuilder sb = new StringBuilder();
sb.Append(“<script language=\”javascript\”>\n”);
sb.Append(“function Redirect()\n”);
sb.Append(“{\n”);
sb.Append(”     window.parent.location.href = \”" + ResolveUrl(myURL) + “\”;\n”);
sb.Append(“}\n”);
sb.Append(“</script>\n”);

Page.ClientScript.RegisterClientScriptBlock(this.GetType(), “Redirect”, sb.ToString());
myBtn.Attributes.Add(“onclick”, “return Redirect();”);

J | Programming | No comments Jump to the top of this page

How to remove all special characters from a string

December 27th, 2007

protected string StripSpecChars(string txtIn)
{
    string txtOut = Regex.Replace(txtIn, @”[^\w\.@-]”, “”).Trim();
    return txtOut;
}

J | Programming | No comments Jump to the top of this page

How to remove commonly occuring English words from a string

December 20th, 2007

I’m using this function to filter common words out of a search query.

protected string removeCommonWords(string sourceStr)
{
    string[] seperator = { ” “ };
    string[] ignoreWords = { “a”, “all”, “am”, “an”, “and”, “any”, “are”, “as”,
        “at”, “be”, “but”, “can”, “did”, “do”, “does”, “for”, “from”, “had”,
        “has”, “have”, “here”, “how”, “i”, “if”, “in”, “is”, “it”, “no”, “not”,
        “of”, “on”, “or”, “so”, “that”, “the”, “then”, “there”, “this”, “to”,
        “too”, “up”, “use”, “what”, “when”, “where”, “who”, “why”, “you” };
    string[] outputStr = { };

    outputStr = sourceStr.ToLower().Split(seperator, StringSplitOptions.RemoveEmptyEntries);

    foreach (string unwantedWord in ignoreWords)
    {
        int index = Array.IndexOf(outputStr, unwantedWord);

        if (index != -1)
        {
            string[] copyStrArr = new string[outputStr.Length - 1];

            // copy the elements before the found index
            for (int i = 0; i < index; i++)
            {
                copyStrArr[i] = outputStr[i];
            }

            // copy the elements after the found index
            for (int i = index; i < copyStrArr.Length; i++)
            {
                copyStrArr[i] = outputStr[i + 1];
            }

            outputStr = copyStrArr;
        }
    }

    sourceStr = string.Join(” “, outputStr);

    return sourceStr;
}

Let me know if you guys have a better solution. :)

J | Programming | 1 comment Jump to the top of this page


Recently on Flickr

  • IMG_0514
  • IMG_0506
  • IMG_0505
  • IMG_0503
  • IMG_0497
  • IMG_0495
  • IMG_0494
  • IMG_0493

Switch Theme

Meta