RegularExpressionValidator

  • Thread starter Thread starter Ken Grimmett
  • Start date Start date
K

Ken Grimmett

I have added a REV to an input type of file. I want to make sure that the
only file type that is allowed is a .gif, .jpg, or .jpeg. I develop my site
on my laptop which is running Win XP Pro and my site is hosted on a Win 2000
Advanced server. Here is my problem. When I test it on my local host of
the XP Pro machine the validator works. When I migrate it to the W2K box it
doesn't work. There is no error that is displayed. Is anyone aware of
this. Not sure if it makes a difference or not but the code is in a control
that is displayed.

Here is the code


<%@ import Namespace="ASPNET.StarterKit.Communities" %>
<%@ Register TagPrefix="community" Namespace="ASPNET.StarterKit.Communities"
Assembly="ASPNET.StarterKit.Communities" %>
<%@ Control %>
<%--

This skin is used both for adding and editing a photo. Modify the HTML
content
to modify the appearance of the page.
--%>
<community:SectionTitle CssClass="Form_Title" Runat="server"
id="SectionTitle1" />
<p class="Form_Description">Use this form to upload images to the portal.
You can
rename files before uploading them.</p>
<p>
<community:DisplayQuota runat="server" id="DisplayQuota1" />
</p>
<TABLE id="Table2" cellSpacing="0" cellPadding="3" class="Form_Table"
border="0">
<TR>
<TD class="Form_SectionRow">
Add Photo Form
<DIV></DIV>
</TD>
</TR>
<TR class="Form_LabelRow">
<TD class="Form_LabelText">
<div>
<span class="Form_LabelText">Image File </span>
<community:UploadValidator id="valUpload"
ControlToValidate="txtPhotoFile" Text="(required)" Runat="Server" />
<br>
<span class="Form_HelpText">(For example, C:\Images\Book.jpg)</span>
</div>
<input id="txtPhotoFile" type="file" Size="40" Runat="Server"><br>
<asp:RegularExpressionValidator ControlToValidate="txtPhotoFile"
ID="revTxtPhotoFile" Runat="server" ErrorMessage="Image must be a gif or
jpg/jpeg format."

ValidationExpression="(.*\.([gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG])$)"><
/asp:RegularExpressionValidator>
<br>
<community:DisplayPhotoImage id="imgPhoto" Width="100" Runat="Server" />
</TD>
</TR>
<tr>
<td class="Form_LabelText">
<asp:Panel id="pnlTopics" runat="Server">
<SPAN class="Form_LabelText">Topic</SPAN>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" Runat="server"
CssClass="Form_Field" Text="(required)"
ControlToValidate="dropTopics"
InitialValue="-1"></asp:RequiredFieldValidator>
<BR>
<community:TopicPicker id="dropTopics"
runat="Server"></community:TopicPicker>
</asp:Panel>
</td>
</tr>
<TR>
<TD class="Form_LabelText">
<div>
<span class="Form_LabelText">Name </span>
<br>
<span class="Form_HelpText">(For example, 'Summer Trip')</span>
<asp:RequiredFieldValidator ControlToValidate="txtPhotoTitle"
Text="(required)" CssClass="Form_Field" Runat="server"
id="RequiredFieldValidator2" />
</div>
<asp:TextBox id="txtPhotoTitle" CssClass="Form_Field" Columns="40"
runat="server"></asp:TextBox>
<P></P>
</TD>
</TR>
<TR>
<TD class="Form_LabelText" colSpan="2">
<div>
<span class="Form_LabelText">Caption </span>
<br>
<span class="Form_HelpText">(This information is listed on the Pictures
page.)</span>
<asp:RequiredFieldValidator ControlToValidate="txtPhotoBriefDescription"
Text="(required)" Display="Dynamic"
CssClass="Form_Field" Runat="server" id="RequiredFieldValidator3" />
<community:LengthValidator Maxlength="500"
ControlToValidate="txtPhotoBriefDescription" Text="(less than 500
characters)"
CssClass="Form_Field" Runat="server" id="LengthValidator1" />
</div>
<asp:TextBox id="txtPhotoBriefDescription" CssClass="Form_Field"
runat="server" TextMode="MultiLine"
Rows="5" Width="508px"></asp:TextBox>
<P></P>
</TD>
</TR>
<TR>
<TD class="Form_LabelText" colSpan="2">
<div>
<span class="Form_LabelText">Full Description</span>
<br>
<span class="Form_HelpText">(Optional. Users can access this information
when they press the 'Read More' link.)</span>
</div>
<community:HtmlTextBox id="txtPhotoFullDescription" runat="server"
Rows="5" Width="508px" />
</TD>
</TR>
<TR>
<TD align="right" colSpan="2" class="Form_SectionRow">
<asp:Button id="btnAdd" CssClass="Form_Button" Runat="server" Text="Add
New Image"></asp:Button>
<asp:Button id="btnEdit" CssClass="Form_Button" Runat="server"
Text="Apply Changes"></asp:Button>
</TD>
</TR>
</TABLE>
<p>
</p>
 
Do you have a ValidationSummary that you are using? Also, in your code
behind, if you want to validate on the server, you should explicitly do a
Page.Validate(), followed by an if (Page.IsValid) {...}.

For client side validation, you also need to make sure you have run
aspnet_regiis on the specific site you are installing to, and you need to do
this again for each new web site that you create on the server. This
installs the script libraries that are used by validation.

--
Chris Jackson
Software Engineer
Microsoft MVP - Windows Client
Windows XP Associate Expert
--
More people read the newsgroups than read my email.
Reply to the newsgroup for a faster response.
(Control-G using Outlook Express)
--

Ken Grimmett said:
I have added a REV to an input type of file. I want to make sure that the
only file type that is allowed is a .gif, .jpg, or .jpeg. I develop my site
on my laptop which is running Win XP Pro and my site is hosted on a Win 2000
Advanced server. Here is my problem. When I test it on my local host of
the XP Pro machine the validator works. When I migrate it to the W2K box it
doesn't work. There is no error that is displayed. Is anyone aware of
this. Not sure if it makes a difference or not but the code is in a control
that is displayed.

Here is the code


<%@ import Namespace="ASPNET.StarterKit.Communities" %>
<%@ Register TagPrefix="community" Namespace="ASPNET.StarterKit.Communities"
Assembly="ASPNET.StarterKit.Communities" %>
<%@ Control %>
<%--

This skin is used both for adding and editing a photo. Modify the HTML
content
to modify the appearance of the page.
--%>
<community:SectionTitle CssClass="Form_Title" Runat="server"
id="SectionTitle1" />
<p class="Form_Description">Use this form to upload images to the portal.
You can
rename files before uploading them.</p>
<p>
<community:DisplayQuota runat="server" id="DisplayQuota1" />
</p>
<TABLE id="Table2" cellSpacing="0" cellPadding="3" class="Form_Table"
border="0">
<TR>
<TD class="Form_SectionRow">
Add Photo Form
<DIV></DIV>
</TD>
</TR>
<TR class="Form_LabelRow">
<TD class="Form_LabelText">
<div>
<span class="Form_LabelText">Image File </span>
<community:UploadValidator id="valUpload"
ControlToValidate="txtPhotoFile" Text="(required)" Runat="Server" />
<br>
<span class="Form_HelpText">(For example, C:\Images\Book.jpg)</span>
</div>
<input id="txtPhotoFile" type="file" Size="40" Runat="Server"><br>
<asp:RegularExpressionValidator ControlToValidate="txtPhotoFile"
ID="revTxtPhotoFile" Runat="server" ErrorMessage="Image must be a gif or
jpg/jpeg format."

ValidationExpression="(.*\.([gG][iI][fF]|[jJ][pP][gG]|[jJ][pP][eE][gG])$)"><
/asp:RegularExpressionValidator>
<br>
<community:DisplayPhotoImage id="imgPhoto" Width="100" Runat="Server" />
</TD>
</TR>
<tr>
<td class="Form_LabelText">
<asp:Panel id="pnlTopics" runat="Server">
<SPAN class="Form_LabelText">Topic</SPAN>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" Runat="server"
CssClass="Form_Field" Text="(required)"
ControlToValidate="dropTopics"
InitialValue="-1"></asp:RequiredFieldValidator>
<BR>
<community:TopicPicker id="dropTopics"
runat="Server"></community:TopicPicker>
</asp:Panel>
</td>
</tr>
<TR>
<TD class="Form_LabelText">
<div>
<span class="Form_LabelText">Name </span>
<br>
<span class="Form_HelpText">(For example, 'Summer Trip')</span>
<asp:RequiredFieldValidator ControlToValidate="txtPhotoTitle"
Text="(required)" CssClass="Form_Field" Runat="server"
id="RequiredFieldValidator2" />
</div>
<asp:TextBox id="txtPhotoTitle" CssClass="Form_Field" Columns="40"
runat="server"></asp:TextBox>
<P></P>
</TD>
</TR>
<TR>
<TD class="Form_LabelText" colSpan="2">
<div>
<span class="Form_LabelText">Caption </span>
<br>
<span class="Form_HelpText">(This information is listed on the Pictures
page.)</span>
<asp:RequiredFieldValidator
ControlToValidate="txtPhotoBriefDescription"
Text="(required)" Display="Dynamic"
CssClass="Form_Field" Runat="server" id="RequiredFieldValidator3" />
<community:LengthValidator Maxlength="500"
ControlToValidate="txtPhotoBriefDescription" Text="(less than 500
characters)"
CssClass="Form_Field" Runat="server" id="LengthValidator1" />
</div>
<asp:TextBox id="txtPhotoBriefDescription" CssClass="Form_Field"
runat="server" TextMode="MultiLine"
Rows="5" Width="508px"></asp:TextBox>
<P></P>
</TD>
</TR>
<TR>
<TD class="Form_LabelText" colSpan="2">
<div>
<span class="Form_LabelText">Full Description</span>
<br>
<span class="Form_HelpText">(Optional. Users can access this information
when they press the 'Read More' link.)</span>
</div>
<community:HtmlTextBox id="txtPhotoFullDescription" runat="server"
Rows="5" Width="508px" />
</TD>
</TR>
<TR>
<TD align="right" colSpan="2" class="Form_SectionRow">
<asp:Button id="btnAdd" CssClass="Form_Button" Runat="server" Text="Add
New Image"></asp:Button>
<asp:Button id="btnEdit" CssClass="Form_Button" Runat="server"
Text="Apply Changes"></asp:Button>
</TD>
</TR>
</TABLE>
<p>
</p>
 
Back
Top