Click here to Skip to main content
15,881,812 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.7K   457   39  
A smart form control that fixes many of the problems that are caused by extensionless URL rewriting in ASP.NET.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RealPage.aspx.cs" Inherits="SmartFormSample_RealPage" %>

<!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>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        This is the real page. my address is 
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br /><br />

        <div style="float: left;width: 300px;margin-right: 20px">
            What is your name? <br />
            <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
                ErrorMessage="Please enter a name.">*</asp:RequiredFieldValidator>
            <asp:Button ID="Button1" runat="server" Text="Go" OnClick="Button1_Click" /><br />
            <asp:Label ID="Label2" runat="server" Text=""></asp:Label>
        </div>
        <div style="">
            <asp:ValidationSummary ID="ValidationSummary1" runat="server" />
        </div><br style="clear:both" /><br />
        <strong>The form tag on this page is:</strong><br />
        <div id="resultDiv">
        
        </div>
        <br />
    </div>
    <script type="text/javascript">
    (function ()
    {
        var resultDiv = document.getElementById("resultDiv");
        var formTag = document.forms(0);
        if (formTag != undefined && formTag != null &&
        resultDiv != undefined && resultDiv != null)
        {
            var tagCode = (formTag.outerHTML) ? formTag.outerHTML : "";
            if (tagCode.length > 0 && tagCode.indexOf(">") > -1)
            {
                tagCode = tagCode.substr(0, tagCode.indexOf(">") + 1);
            }
//            tagCode = tagCode.replace("<", "&lt;");
//            tagCode = tagCode.replace(">", "&gt;");
            resultDiv.appendChild(document.createTextNode(tagCode));
        }
    })();
    </script>
    </form>
</body>
</html>

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