Click here to Skip to main content
15,895,011 members
Articles / Web Development / HTML

AJAX Dirty-Panel

Rate me:
Please Sign up or sign in to vote.
3.79/5 (22 votes)
30 Apr 20072 min read 95.1K   464   60  
This is a Panel that automatically shows an alert if the user tries to leave the page before saving the data.
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%@ Register Assembly="DirtyPanel" Namespace="DirtyPanel" TagPrefix="dp" %>
<%@ Register Assembly="Anthem" Namespace="Anthem" TagPrefix="Anthem" %>
<!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>
    Change any field and click "Leave the page"
    <br /><br />
    <dp:DirtyPanel runat="server" ID="pnDirty" onleavemessage="Do you really want to leave without saving?" >
    <table>
        <tr>
            <td>
                TextBox: 
            </td>
            <td>
                <Anthem:TextBox runat="server" ID="txtField" />
            </td>
        </tr>
        <tr>
            <td>
                DropDownList: 
            </td>
            <td>
                <asp:DropDownList runat="server" ID="ddlField" >
                    <asp:ListItem>Item 1</asp:ListItem>
                    <asp:ListItem>Item 2</asp:ListItem>
                    <asp:ListItem>Item 3</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>    
        <tr>
            <td>
                CheckBox: 
            </td>
            <td>
                <Anthem:CheckBox runat="server" ID="chkField" />
            </td>
        </tr>
          <tr>
            <td>
                RadioButton: 
            </td>
            <td>
                <Anthem:RadioButton runat="server" ID="rbField1" GroupName="radio" />&nbsp;
                <Anthem:RadioButton runat="server" ID="rbField2" GroupName="radio" />
            </td>
        </tr>
        <tr>
            <td>
                TextArea: 
            </td>
            <td>
                <Anthem:TextBox runat="server" ID="txtField2" TextMode="MultiLine" />
            </td>
        </tr>
        <tr>
            <td>
                DataGrid:
            </td>
            <td>
                <asp:DataGrid runat="server" ID="dgFields" AutoGenerateColumns="false">
                    <Columns>
                        <asp:TemplateColumn HeaderText="Column 1">
                            <ItemTemplate>
                                <asp:TextBox runat="server" ID="txtGrid" />
                            </ItemTemplate>
                        </asp:TemplateColumn>
                    </Columns>
                </asp:DataGrid>
            </td>
        </tr>
    </table>
    </dp:DirtyPanel>    
    </div>
    <a href="http://www.csharping.com">Leave the page</a>
    &nbsp;&nbsp;&nbsp;
    <Anthem:Button runat="server" ID="btnSave" Text="Save" />
    </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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior) Intelligent Coder
Canada Canada
I've been developing .NET enterprise applications since 2000.

I am originally from Rio de Janeiro and I am currently working at http://www.intelligentcoder.com in Ontario.

I also have my own startup where we offer client intake forms.

Comments and Discussions