How to put errors in the Validation Summary

Last post 10-20-2010, 10:32 PM by Kenneth. 3 replies.
Sort Posts: Previous Next
  •  10-04-2010, 7:56 PM 64321

    How to put errors in the Validation Summary

    Our department forbids the use of JavaScript alert due to accessibility issues with blind people.  Is there a way to show the file too large error in the asp.net validation summary control instead?

    Filed under:
  •  10-10-2010, 9:56 PM 64384 in reply to 64321

    Re: How to put errors in the Validation Summary

    Hi microcontroleur,
     
    The example below shows you how to catch the error message of uploader and use your own method to show you own message.
     
    1. <%@ Page Language="C#" %>  
    2.   
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    4. <html xmlns="http://www.w3.org/1999/xhtml">  
    5. <head runat="server">  
    6.     <title>Untitled Page</title>  
    7. </head>  
    8. <body>  
    9.     <form id="form1" runat="server">  
    10.         <CuteWebUI:UploadAttachments ID="attachment1" runat="server" InsertText="Upload1">  
    11.             <ValidateOption MaxSizeKB="10" />  
    12.         </CuteWebUI:UploadAttachments>  
    13.              <asp:Label ID="errorMessage" runat="server"></asp:Label>  
    14.     </form>  
    15. </body>  
    16. </html>  
    17.   
    18. <script>  
    19.    function CuteWebUI_AjaxUploader_OnError(msg)  
    20.     {  
    21.         //Catch errors  
    22.         if(msg.indexOf("is too large")!=-1)  
    23.         {  
    24.             //show the message you want  
    25.             var errorMessage=document.getElementById("<%= errorMessage.ClientID %>");  
    26.             errorMessage.innerHTML="The file is too large";  
    27.             return false;  
    28.         }  
    29.     }  
    30. </script> 
    Regards,
     
    ken
  •  10-14-2010, 12:24 PM 64433 in reply to 64384

    Re: How to put errors in the Validation Summary

    Your method doesn't work.  I still have that javascript pop-up.
  •  10-20-2010, 10:32 PM 64544 in reply to 64433

    Re: How to put errors in the Validation Summary

    Hi microcontroleur,
     
    Please try the example below. I integrated the error message into the Validation Summary control.
     
    1. <%@ Page Language="C#" %>  
    2.   
    3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    4. <html xmlns="http://www.w3.org/1999/xhtml">  
    5. <head runat="server">  
    6.     <title>Untitled Page</title>  
    7. </head>  
    8. <body>  
    9.     <form id="form1" runat="server">  
    10.         <table border="1">  
    11.             <tr>  
    12.                 <td>  
    13.                     Name:  
    14.                     <asp:TextBox ID="textBox1" runat="server"></asp:TextBox>  
    15.                 </td>  
    16.                 <asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="textBox1"  
    17.                     runat="server" ErrorMessage="please type your name"></asp:RequiredFieldValidator>  
    18.             </tr>  
    19.             <tr>  
    20.                 <td>  
    21.                     <CuteWebUI:UploadAttachments ID="UploadAttachments1" runat="server">  
    22.                         <ValidateOption MaxSizeKB="1" />  
    23.                     </CuteWebUI:UploadAttachments>  
    24.                     <asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="textBox2"  
    25.                         runat="server" ErrorMessage="the file is too large!"></asp:RequiredFieldValidator>  
    26.                 </td>  
    27.             </tr>  
    28.         </table>  
    29.         <br />  
    30.         <asp:Button ID="button1" runat="server" Text="Submit(start verification)" />  
    31.         <asp:ValidationSummary ID="ValidationSummary1" runat="server" />  
    32.         <asp:TextBox ID="textBox2" runat="server" Text="textBox2" Style="visibility: hidden"></asp:TextBox>  
    33.     </form>  
    34. </body>  
    35. </html>  
    36.   
    37. <script>  
    38.    function CuteWebUI_AjaxUploader_OnError(msg)  
    39.   
    40.     {  
    41.         if(msg.indexOf("is too large")!=-1)  
    42.   
    43.         {  
    44.             var textBox2=document.getElementById("<%= textBox2.ClientID %>");  
    45.             textBox2.value="";  
    46.                    return false;  
    47.         }  
    48.   
    49.     }  
    50. </script> 

     Regards,
     
    ken
View as RSS news feed in XML