A Couple Must Read ASP.NET Articles

June 10, 2008 21:13 by Dominick

Speed up access to your favorite frameworks via the AJAX Libraries API

This is just a fantastic idea. It's very simple. Use Google's extensive infrastructure to serve those common JavaScript libraries you love to use. I've recently started using jQuery so all I have to do is point the link to the URL provided by Google and that's 17kb per request my server won't have to turn out. Thanks, Google!

CSS Message Boxes for different message types 

This comes from one of the best new sites out there "Janko At Warp Speed". This article shows us how to handle a few common message types within our applications. It's all CSS and very sharp!



Tags:
Categories: ASP.NET | Tip/Trick | General | Javascript
Actions: E-mail | Permalink | Comments (0) | Comment RSSRSS comment feed


A Few Quick Tips to Get More Visitors

November 28, 2007 19:46 by Dominick

Its fairly easy to get people to visit your website. All you need is a few dollars for advertising and you can get people on your site. The problem is getting people to actually stay and interact. I would guess that around 1% of the people that arrive from Google advertisements actually stay around and/or come back. That's not a very good rate if you ask me. Is it worth the money? Not at all. Its just my opinion, but I think using Google Adwords should only be used when you first start up your site and have no other way of becoming visible.

The best way I've found to get people to hang around is posting stories on social bookmarking sites like DotNetKicks, DZone and Digg. This is nothing groundbreaking, but you should know that these are wonderful sources of "free" traffic if you don't already. The visitors tend to stay longer, read related posts and even sign up for your rss feeds. You just never know what's going to be a "hit" and cause lots of traffic to come your way.  I had a story about SubSonic make the main page on DotNetKicks and DZone at the same time. That was fun and very satisfying. 

I tried StumbleUpon's advertising service for another site, ConservativeKicks.com, but the results were even less impressive than the Google ads. I recommend these actions when you start a new web site:

  • Start posting comments on related websites (make sure you have links back to your website in your sig)
  • Buy some Google ad space. You've got to get people on your site, but don't go overboard. Set a daily budget you can afford
  • Post links to your posts on social bookmarking sites. They are the best way to drive traffic to your site
  • Submit your site to StumbleUpon and consider using their paid service because it does drive a lot of traffic to your site and you never know what will make them stay on your site.
  • Make friends with other website owners. Cross-site linking can help everyone involved.
kick it on DotNetKicks.com

Tags:
Categories: ASP.NET | SubSonic | General
Actions: E-mail | Permalink | Comments (1) | Comment RSSRSS comment feed


3 Open Source Apps I'm Thankful For

November 21, 2007 22:17 by Dominick

Its the time of year again (for us in the US) to stuff ourselves even more than usual. I love turkey and all the other traditional Thanksgiving foods. Its a day where I tend to lose all self control.

I'm thankful for the following things (.NET related):

  1. SubSonic

    The program I use the most by far. I use it in nearly every new project I start. It has saved me an incredible amount of time over the last year. Its all about finding ways of being more productive and eliminating CRUD. I spent too many years coding SQL right into my pages. Bad times. I can't say too many good things about SubSonic. Its worth using now just to be ready for when its included in some later version of dotnet.

  2. DotNetKicks

    The site and the open source software. I've been visiting DotNetKicks.com for most of this last year and I consider it to the leading resource for everything dotnet. I love the site and I love the open source software powering it. I liked it so much that I started my own site, ConservativeKicks.com, with it. It was a pain to get going, but it was well worth it. It also uses SubSonic so its easy as pie to deal with on the backend.

  3. BlogEngine.NET

    I use this software for this blog. It was very simple to setup and get going. It has all the features I need and it just works. I suggest giving it a try if you're looking for a good blogging engine. It doesn't use SubSonic, but I'm not looking for an application that I'll need to customize too much. I just want to hit start and write. BlogEngine.NET does that very well.

Happy Thanksgiving, everybody. Be safe and have fun. See you all after the holiday. 

Tags:
Categories: ASP.NET | Open Source | SubSonic | General
Actions: E-mail | Permalink | Comments (7) | Comment RSSRSS comment feed


Howto: Create a Custom Control in ASP.NET (C#)

October 30, 2007 12:34 by Dominick

Introduction

Creating custom controls can save you a lot of time and effort when building an application. The built-in sever controls provided can do just about anything you need them to, but sometimes it takes a great deal of coding (hacking) to make it do exactly what you want it to do. Consider the possibility that you need a textbox control that you would like to be able to assign a readony property to it so it either renders as a regular textbox if false or plain text if true. You may also want a textbox that will cause it's on "OnTextChanged" to bubble up in the "GridViewCommandEvent" of a Gridview control. By default the textbox does not support that.

Afterwards there will be Cake

Create a new Web Control Library project within the solution you want to add the control to. Here is the location to do so in my Visual Studio installation.



Visual Studio has created a file called "WebCustomControl1.cs" within that project. You can rename it to whatever you like. This file is where you can insert the code that I'll show below. I'm going to show you the entire code right now. I've put some comments in to explain what's going on. Just copy and paste this code inside the cs file.

using System;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace CustomControls.UI.Controls
{
    [DefaultProperty("Text")]
    [ToolboxData("<{0}:CustomTextBox runat=server></{0}:CustomTextBox>")]
    public class CustomTextBox : TextBox //with this you can override all the normal "stuff" within the textbox control
    {

       //Here are the properties that will be used for the command event

        [Bindable(true)]
        [Category("Custom")]
        [DefaultValue("")]
        [Localizable(true)]
        public string CommandName
        {
            get
            {
                string s = ViewState["CommandName"] as string;
                return s == null ? String.Empty : s;
            }
            set
            {
                ViewState["CommandName"] = value;
            }
        }

        [Bindable(true)]
        [Category("Custom")]
        [DefaultValue("")]
        [Localizable(true)]
        public string CommandArgument
        {
            get
            {
                string s = ViewState["CommandArgument"] as string;
                return s == null ? String.Empty : s;
            }
            set
            {
                ViewState["CommandArgument"] = value;
            }
        }

        [Bindable(true)]
        [Category("Custom")]
        [DefaultValue("False")]
        [Localizable(true)]
        public string IsReadOnly
        {
            get
            {
                string s = ViewState["IsReadOnly"] as string;
                return s == null ? String.Empty : s;
            }
            set
            {
                ViewState["IsReadOnly"] = value;
            }
        }
        
        protected static readonly object EventCommandObj = new object();

        public event CommandEventHandler Command
        {
            add
            {
                Events.AddHandler(EventCommandObj, value);
            }
            remove
            {
                Events.RemoveHandler(EventCommandObj, value);
            }
        }

        //this will raise the bubble event
        protected virtual void OnCommand(CommandEventArgs commandEventArgs)
        {
            CommandEventHandler eventHandler = (CommandEventHandler)Events[EventCommandObj];
            if (eventHandler != null)
            {
                eventHandler(this, commandEventArgs);
            }
            base.RaiseBubbleEvent(this, commandEventArgs);
        }

        //this overrides the OnTextChanged event on the normal textbox
        protected override void OnTextChanged(EventArgs e)
        {
            base.OnTextChanged(e);

            if (AutoPostBack)
            {
                //pass the event arguments to the OnCommand event to bubble up
                CommandEventArgs args = new CommandEventArgs(this.CommandName, this.CommandArgument);
                OnCommand(args);
            }
        }

        protected override void CreateChildControls()
        {
            base.CreateChildControls();
        }

        protected override void Render(HtmlTextWriter writer)
        {
            //if its readonly then render the text in a span tag
            if (IsReadOnly == "True")
            {
                writer.AddAttribute(HtmlTextWriterAttribute.Id, this.ClientID);
                writer.RenderBeginTag(HtmlTextWriterTag.Span);
                writer.Write(this.Text);
                writer.RenderEndTag();
            }
            else
            {
                //if not then render the textbox
                base.Render(writer);
            }
        }
    }
}

The Cake is a Lie

Now anytime you need to have the OnTextChanged event fire and bubble up within a Gridview than just use this control. It will also be very handy to do able to cause the textbox to become truely readonly.

 

kick it on DotNetKicks.com



SubSonic Quickie - How to Delete using the Query Tool

October 29, 2007 12:37 by Dominick
Here's a quick little bit of code that shows how to delete records in your database using SubSonic's Query Tool. I know you can write this is fewer lines of code, but I think this shows a little more clearly what's going on.
Query qryDelete = new Query(DeliverableCategoriesSelected.Schema);
qryDelete.QueryType = QueryType.Delete;
// You can also do the following line in this way: qryDelete.WHERE("ProductId", productId);
qryDelete.WHERE(Products.Columns.ProductId, productId); //where productId equals the product ID number you want to delete
qryDelete.Execute();
SubSonic also supports logical deletes so if you have your tables setup with the extra fields (isDeleted being the most important) than you record will not disappear. You can still do that with the "Destroy" method if you really feel the need to kill something.