> lbl.Text = "<script language='javascript'>" & Environment.NewLine &
Once again...
lbl.Text = "<script type=""text/javascript"">" & Environment.NewLine &
The language tag has been deprecated for some time...
> MessageBox
Will someone be logged on to the server to see that...?

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
James Page - 11 Mar 2008 02:18 GMT
Thanks I'll change that.
Logged on??
>> lbl.Text = "<script language='javascript'>" & Environment.NewLine &
>
[quoted text clipped - 7 lines]
>
> Will someone be logged on to the server to see that...?
Mark Rae [MVP] - 11 Mar 2008 02:46 GMT
>>> lbl.Text = "<script language='javascript'>" & Environment.NewLine &
>>
[quoted text clipped - 5 lines]
>
> Thanks I'll change that.
>>> MessageBox
>>
>> Will someone be logged on to the server to see that...?
>
> Logged on??
Yes - you are using MessageBox in your server-side code... For one thing,
shouldn't it be MessageBox.Show(...)? And where do you expect this message
box to display...?

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
James Page - 11 Mar 2008 12:09 GMT
MessageBox is the subroutine that is called if the select case fails and
passes string back to it and display a client side alertbox.
Here's the full code:
Private Sub MessageBox(ByVal strMsg As String)
' define a javascript alertbox containing
' the string passed in as argument
' create a new label
Dim lbl As New Label()
' add the javascript to fire an alertbox to the label and
' add the string argument passed to the subroutine as the
' message payload for the alertbox
lbl.Text = "<script type=""text/javascript"">" &
Environment.NewLine & "window.alert('" + strMsg + "')</script>"
' add the label to the page to display the alertbox
Page.Controls.Add(lbl)
End Sub
Private Sub FormView1_ItemInserting(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.FormViewInsertEventArgs) Handles
FormView1.ItemInserting
'Reference the FileUpload control
Dim UploadedFilePic As FileUpload =
CType(FormView1.FindControl("fileUploadProdPict"), FileUpload)
'Make sure we are dealing with a JPG, GIF or PNG file
Dim extensionPic As String =
Path.GetExtension(UploadedFilePic.PostedFile.FileName).ToLower()
Dim filenamePic As String =
Path.GetFileName(UploadedFilePic.PostedFile.FileName)
Dim MIMETypePic As String = Nothing
Select Case extensionPic
Case ".gif"
MIMETypePic = "image/gif"
Case ".jpg", ".jpeg", ".jpe"
MIMETypePic = "image/jpeg"
Case ".png"
MIMETypePic = "image/png"
Case Else
MessageBox("Product picture:\r\nOnly .gif, .jpg and
.png file types\r\ncan be selected for upload to database.")
UploadedFilePic.Focus()
e.Cancel = True
Exit Sub
End Select
'Specify the values for the MIMEType and ImageData parameters
e.Values("productPicMimeType") = MIMETypePic
'Load FileUpload's InputStream into Byte array
Dim
imageBytesPic(UploadedFilePic.PostedFile.InputStream.Length) As Byte
UploadedFilePic.PostedFile.InputStream.Read(imageBytesPic, 0,
imageBytesPic.Length)
e.Values("productPic") = imageBytesPic
e.Values("productPicFileName") = filenamePic
End Sub
Therefore if the item Inserting event fails, at the select case stage,
the user is prompted to try again. I know its not the technically
correct solution but it does work. Ideally i'd like full client side
validation before the item inserting event is fired but javascript is
not my strong suit!
>>>> lbl.Text = "<script language='javascript'>" & Environment.NewLine &
>>>
[quoted text clipped - 15 lines]
> thing, shouldn't it be MessageBox.Show(...)? And where do you expect
> this message box to display...?
Mark Rae [MVP] - 11 Mar 2008 13:10 GMT
>>> Logged on??
>>
[quoted text clipped - 4 lines]
> MessageBox is the subroutine that is called if the select case fails and
> passes string back to it and display a client side alertbox.
Ah - OK...

Signature
Mark Rae
ASP.NET MVP
http://www.markrae.net
Labels are not the best place to attach text, due to the order in which they
display. I am not completely convinced it will not work, but I still find
attaching to a Panel is better.
Also, you should note you are mixing server side code and client side. When
someone goes to upload, it will be a single request (multi-part) to the
server, which contains the form information, plus a binary representation of
image someone is uploading. Once you see it is the incorrect image, you are
finished with the server side code, which means your MessageBox() routine
cannot be contacted without creating a second trip to the server. This is
what Mark was talking about.
On your form submit routine, you should check for image type and then either
give the user a success message or a failure message (and/or popup). Do not
try to contact server side code from the client side, except through events.

Signature
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
*************************************************
| Think outside the box!
*************************************************
> Thanks guys this is what i've come up with:
>
[quoted text clipped - 26 lines]
>
> Any comments?