Solved

IE vs Firefox image validation

Posted on 2006-11-19
7
475 Views
Last Modified: 2010-08-05
Hi,

I'm using VB.NET to develop a web app which allows user to upload images however client side validation works with  IE but not Firefox.  Now I am trying to validate based on browser type but it does not work either.  Any ideas?

<TR>
<TD><SPAN class="infotext">Picture:</SPAN></TD>
<TD colSpan="3"><INPUT id="uplPic" type="file" name="uplPic" runat="server">
<%if not(Request.Browser.Browser.Equals("IE")) then%>
<!--this regular experssion works in firefox only-->
<asp:regularexpressionvalidator id="revUpPic" runat="server" ControlToValidate="uplPic" ErrorMessage="MOZ Picture must be a .JPG or .GIF" ValidationExpression="^[0-9A-Za-z_ ]+(.[jJ][pP][gG]|.[gG][iI][fF])$" Font-Bold="True" Font-Size="Medium">*</asp:regularexpressionvalidator></TD>

<%else if (Request.Browser.Browser.Equals("IE")) then %>
<!--this regular experssion works in IE only-->
<asp:regularexpressionvalidator id="revUpPic1" runat="server" ControlToValidate="uplPic" ErrorMessage="IE Picture must be a .JPG or .GIF"
ValidationExpression="^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))+(.gif|.GIF|.jpg|.JPG|.jpeg|.JPEG)$" Font-Bold="True" Font-Size="Medium">*</asp:regularexpressionvalidator></TD>

<%end if%>
</TR>

Thanks.
                                                           
                                             
0
Comment
Question by:r_mason101
  • 3
  • 3
7 Comments
 
LVL 15

Expert Comment

by:Solar_Flare
ID: 17976827
the problem is that client side validation is done in javascript in the browser. you should load the page with firefox and look for any javascript errors it gives, and also look at the page source and find the validation javascript. are you sure that your if else statement is always putting a validator in the rendered page?

0
 

Author Comment

by:r_mason101
ID: 17976852
thanks.

the if statement does not work, it tries to perform both sets of validation.  I did not see any javascript errors in firefox.  What is the simpilest way to implement validtion for the extension thats works in any browser, is it client or server side code?

this is the code i am using for uploading images, can i add some validation somewhere in here?

Dim strImageName As String
        strImageName = "com" & nCommercialID & "A.jpg"
        Dim strPath As String = Server.MapPath("/WantMyLease/commercialImage")

        'If ("" = strImageName) Then
        'lblMemberID.Text = "Error - a file name must be specified."
        'End If

        If Not (uplPic.PostedFile.FileName = "") Then
            Try

                uplPic.PostedFile.SaveAs(strPath + "/" + strImageName)
                lblMemberID.Text = Server.MapPath("/commercialImage")
                generateThumbnail(strImageName)
            Catch ext As Exception
                lblMemberID.Text = "Error saving <b>" & strPath & strImageName & "</b><br>" & ext.ToString()
                '  Return False
            End Try
        End If

Thanks for your help.
0
 
LVL 12

Expert Comment

by:sandip132
ID: 17976878
If validation happens when you tab out of the field then the validation is done with client-side script ASP.NET has
generated. And ASP.NET 1.1 usually generates client-side script geared
towards IE 4 and later using the IE DOM and not the more cross browser
compatible W3C DOM, therefore with the normal settings browsers like
Mozilla, firefox will not get that client-side script at all. Server-side
validation on postback should nevertheless work independent of the
browser and any client-side script ASP.NET might or might not generate.

try using IsValid.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:r_mason101
ID: 17976897
can i get server side code to perform validation?  BTW i am using Page.IsValid

Thanks.
0
 
LVL 12

Expert Comment

by:sandip132
ID: 17976927
try ErrorMsg_ServerValidate function from this code: http://www.codeproject.com/useritems/Custom_File_Upload.asp
0
 

Author Comment

by:r_mason101
ID: 17976946
thanks but i need vb.net code, i am not familiar with c#
0
 
LVL 12

Accepted Solution

by:
sandip132 earned 250 total points
ID: 17977119
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
asp.net bundle 8 47
How can I use this extension method? 8 47
How do ASP.NET and MVC work together? 4 30
ADO.NET ENTITY DATA MODEL 3 32
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now