Click here to Skip to main content
15,893,190 members
Articles / Web Development / ASP.NET

A Smart Form Control for ASP.NET URL Rewriting

Rate me:
Please Sign up or sign in to vote.
4.20/5 (8 votes)
20 Jul 2007CPOL3 min read 58.8K   457   39  
A smart form control that fixes many of the problems that are caused by extensionless URL rewriting in ASP.NET.
using System;
using System.ComponentModel;
using System.Web;
using System.Web.UI;

namespace David.Nelson.UI.Web
{
    /// <summary>
    /// An HtmlTextWriter that provides granular control over
    /// how attributes are written.
    /// </summary>
    public class SelectiveHtmlTextWriter : HtmlTextWriter
    {
        public SelectiveHtmlTextWriter(HtmlTextWriter writer)
            : base(writer.InnerWriter)
        {
        }

        public event SubstituteValueEventHandler WritingAttribute;

        public override void WriteAttribute(string name, string value, bool fEncode)
        {
            string valToWrite = value;
            SubstituteValueEventArgs args = new SubstituteValueEventArgs(name, value);
            if (WritingAttribute != null)
            {
                WritingAttribute(this, args);

                if (args.Cancel == false)
                    valToWrite = args.NewValue;
            }

            if (args.Cancel == false)
                base.WriteAttribute(name, valToWrite, fEncode);
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
I have been doing web development for about 11 years. I specialize in Dynamic HTML, C#, and SQL database design.

Comments and Discussions