Problem on postback with regular expression validator

Last post 01-14-2009 4:17 AM by turibbio. 5 replies.

Sort Posts:

  • Problem on postback with regular expression validator

    01-13-2009, 9:50 AM
    • Member
      39 point Member
    • turibbio
    • Member since 01-03-2008, 3:01 PM
    • Posts 105

    Hi all, I have a problem with regular expression validator. I have a file upload and I want to upload only Excel file. The problem is that after the postback, regular expression validator is shown. This is the code: 

            <asp:FileUpload ID="FileUpload1" runat="server" />
            <asp:Button ID="cmdUpload" runat="server" Text="Upload" ValidationGroup="Validators" /><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="FileUpload1"
                ErrorMessage="Insert a file" ValidationGroup="Validators"></asp:RequiredFieldValidator><br />
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="FileUpload1"
                ErrorMessage="Insert only Excel File" ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.xls|.XLS|.xlsx|.XLSX)$"
                ValidationGroup="Validators"></asp:RegularExpressionValidator>

     

    Thanks in advance!

    There are only 10 types of people in the world: Those who understand binary, and those who don't!
  • Re: Problem on postback with regular expression validator

    01-13-2009, 10:45 AM
    • All-Star
      25,180 point All-Star
    • budugu
    • Member since 01-12-2006, 2:15 PM
    • North Carolina
    • Posts 3,759

    turibbio:
    The problem is that after the postback, regular expression validator is shown.

    The code is working fine for me. Are you getting any errors on post back?

     

    Vijay Kodali || My Blog


    "Don't be afraid to be wrong; otherwise you'll never be right."
  • Re: Problem on postback with regular expression validator

    01-13-2009, 11:28 AM
    • Member
      39 point Member
    • turibbio
    • Member since 01-03-2008, 3:01 PM
    • Posts 105

     no errors, are you sure that it works? I've tried the same code but it shows error. There's maybe a problem of property of control or validation group? Can you post me the whole aspx of your working code? Thanks!

    There are only 10 types of people in the world: Those who understand binary, and those who don't!
  • Re: Problem on postback with regular expression validator

    01-13-2009, 12:10 PM
    Answer
    • All-Star
      25,180 point All-Star
    • budugu
    • Member since 01-12-2006, 2:15 PM
    • North Carolina
    • Posts 3,759

    turibbio:
    no errors, are you sure that it works?
    Sorry, I used another expression. Here is expression i tried.. 
    <asp:FileUpload ID="FileUpload1" runat="server" />
            <asp:Button ID="cmdUpload" runat="server" Text="Upload" ValidationGroup="Validators" /><br />
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="FileUpload1"
                ErrorMessage="Insert a file" ValidationGroup="Validators"></asp:RequiredFieldValidator><br />
            <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" ControlToValidate="FileUpload1"
                ErrorMessage="Insert only Excel File" ValidationExpression ="[a-zA-Z\\].*(.doc|.xls|.XLS|.xlsx|.XLSX)$"
                ValidationGroup="Validators"></asp:RegularExpressionValidator>
                 <asp:Button ID="Button1" runat="server" Text="Button"  />
      
    Vijay Kodali || My Blog


    "Don't be afraid to be wrong; otherwise you'll never be right."
  • Re: Problem on postback with regular expression validator

    01-13-2009, 1:40 PM
    Answer
    • All-Star
      30,305 point All-Star
    • PLBlum
    • Member since 06-28-2002, 1:20 PM
    • Boston, MA
    • Posts 5,343
    • TrustedFriends-MVPs

     The <input type='file'> tag does not always pass back the file path. In particular, it is omitted when <form enctype="multipart/form-data" >

     You should confirm that the FileUpload control actually has the filepath before determining what's wrong with the validator. After all, the regularexpressionvalidator takes no action when it gets an empty string form the textbox.

    --- Peter Blum
    Creator of Peter's Data Entry Suite (formerly Professional Validation And More and Peter's Date Package) and Peter's Polling Package
    www.PeterBlum.com
  • Re: Problem on postback with regular expression validator

    01-14-2009, 4:17 AM
    • Member
      39 point Member
    • turibbio
    • Member since 01-03-2008, 3:01 PM
    • Posts 105

    PLBlum:

     The <input type='file'> tag does not always pass back the file path. In particular, it is omitted when <form enctype="multipart/form-data" >

     You should confirm that the FileUpload control actually has the filepath before determining what's wrong with the validator. After all, the regularexpressionvalidator takes no action when it gets an empty string form the textbox.

     

     

    Thanks for the information Peter! Very Helpful

    There are only 10 types of people in the world: Those who understand binary, and those who don't!
Page 1 of 1 (6 items)