Sunday, October 10, 2010

How to play a sound on error


Demo: 

<%@ Page Language="C#" %>
<html>
<head id="Head1" runat="server">
    <script language="javascript" type="text/javascript">
        function PlaySound() {
            if (typeof (Page_ClientValidate) == "function") {
                Page_ClientValidate();
                if (!Page_IsValid) {
                    var thissound = eval("document.error");
                    thissound.Play();
                    return false;
                }
                return true;
            }
        }
    </script>
</head>
<body style="padding:0margin:0">
    <form runat="server" id="form1">
        <asp:TextBox runat="server" ID="txtName" />
        <asp:RequiredFieldValidator runat="server" ID="rvalName" 
            ErrorMessage="Error" ControlToValidate="txtName" Display="Dynamic" />    
        <hr />
        <asp:Button runat="server" ID="btnSave" Text="Save" OnClientClick="javascript:PlaySound()" />
        <embed src="Resources/Error.wav" autostart="false" width="0" 
            height="0" name="error" enablejavascript="true"></embed>
    </form>
</body>
</html>

No comments:

iPhone Launch Screen Sizes

iPhone Portrait iOS 8 Retina HT 5.5 = 1242 X 2208 Retna HD 4.7 = 750 X 1134 iPhone Landscape iOS 8 Retina HD 5.5  2208 X 1242 iPho...