Home > ASP Development > Call Sub Runat Server Type Mismatch

Call Sub Runat Server Type Mismatch



Hi,



I've written a simple sub to delete a photo (linked to a specific success story) when clicking on a button underneath the photo:



This is an extract from the code in the body:




Code:


<%
...................
strSuccessStoryID = rs("SuccessStoryID")
strAtt1 = rs("Att1")
.......................
%>

' rs("Att1") would hold a value such as pic1.jpg

<input type="button" value="Remove" language="VBScript" onClick="Call DeletePhotoE(<%=strSuccessStoryID%>, '<%=strAtt1%>')">






Here's the Sub:




Code:


<SCRIPT language="VBScript">
Sub DeletePhotoE(ID, Photo)

Dim rc, strAnswer
rc = MsgBox ("Are you sure that you want to delete this photo?", vbYesNo, "Sure?")
strAnswer = rc
If strAnswer = 6 Then
location.href = "photo_delete.asp?SuccessStoryID="&ID&"&Photo="&Photo&"&Submit=True"
End If

End Sub

</SCRIPT>






This works perfectly in IE without RUNAT="Server" in the script tag, but it won't work in Netscape or Opera.



The moment I add RUNAT="Server" in the script tag, though, I get an error message: Type Mismatch 'DeletePhotoE'.



I'm not sure what could cause this: strSuccessStoryID is just an integer, and strAtt1 is a string, but I did put it inside '....'.



Any help to solve this will be appreciated!

    
Guest


The DeletePhotoE is in vbScript which will only run in IE.



Once you try and run it on the server you are going to get

other problems caused by MsgBox - it is not available on the

server.



Try this instead it uses javascript




Code:



<script type="text/javascript">
function deletePhoto(ID, Photo) {
if (confirm("Are you sure that you want to delete this photo?")) {
document.location.href = "photo_delete.asp?SuccessStoryID="&ID&"&Photo="&Photo&"&Submit=True";
}
}
</script>

<input type="button" value="Remove" onClick="deletePhoto(<%=strSuccessStoryID%>, '<%=strAtt1%>');">



Was this answer helpful ? Yes No   
Guest


you don't have and better not use client side scripting for such task.

pure HTML is way better in any sense:


Code:



<form action="photo_delete.asp" method="GET">
<input type="hidden" name="SuccessStoryID" value="<%=strSuccessStoryID%>" />
<input type="hidden" name="Photo" value="<%=strAtt1%>" />
<input type="hidden" name="Submit" value="True" />
<button type="submit">Remove</button>
</form>



Was this answer helpful ? Yes No   
Guest


Quote:
Originally Posted by Shadow Wizard
you don't have and better not use client side scripting for such task.

pure HTML is way better in any sense:


Code:



<form action="photo_delete.asp" method="GET">
<input type="hidden" name="SuccessStoryID" value="<%=strSuccessStoryID%>" />
<input type="hidden" name="Photo" value="<%=strAtt1%>" />
<input type="hidden" name="Submit" value="True" />
<button type="submit">Remove</button>
</form>






Except there is no confirmation....

Was this answer helpful ? Yes No   
Guest


Thanks for your feedback, eiljahthegold and Shadow Wizard. I have gone the JavaScript way and it's working now. Just had to make one small change...



document.location.href = "photo_delete.asp?SuccessStoryID="+ID+"&Photo="+Photo+"&Submit=True";



On the same website, I have another page where product prices are being displayed in the local currency - ZAR (read from an Access database). First, the user selects his preferred currency, which then calculates and displays the unit price in the selected currency. Next he enters the number of units that he requires of each product. It should then calculate and display sub totals, VAT and Totals.



Again, I've written a VBScript function (which only works in IE ):




Code:


Function CalcSubTotal(ID,CurrencyUnit,UnitPrice,VAT,Qty)

i = ID - 1

If IsNumeric(Qty) = True Then
SubTotal = FormatNumber(CDBL(UnitPrice),2,-1)*Qty
SubTotalVAT = VAT*Qty
If CurrencyUnit = 3 Then
curEuros = FormatNumber(SubTotal, 2) & "€"
Execute "frm1.SubTotal("&i&").Value = curEuros"
Else
Execute "frm1.SubTotal("&i&").Value = FormatCurrency(SubTotal, 2, -1, 0, 0)"
End If

If frm1.Units.Value = "" Then
TotalUnits = Qty
Else
TotalUnits = frm1.Units.Value + 1*Qty
End If

If frm1.Total.Value = "" Then
TotalPriceSub = SubTotal
TotalPriceVAT = SubTotalVAT
TotalPrice = TotalPriceSub + TotalPriceVAT
Else
TotalPriceSub = frm1.SubTotals.Value + SubTotal
TotalPriceVAT = frm1.SubTotalsVAT.Value + SubTotalVAT
TotalPrice = TotalPriceSub + TotalPriceVAT
End If

Execute "frm1.Units.Value = TotalUnits"
If CurrencyUnit = 3 Then
curEuros2 = FormatNumber(TotalPriceSub, 2) & "€"
Execute "frm1.SubTotals.Value = curEuros2"
curEuros3 = FormatNumber(TotalPriceVAT, 2) & "€"
Execute "frm1.SubTotalsVAT.Value = curEuros3"
curEuros4 = FormatNumber(TotalPrice, 2) & "€"
Execute "frm1.Total.Value = curEuros4"
Else
Execute "frm1.SubTotals.Value = FormatCurrency(TotalPriceSub, 2, -1, 0, 0)"
Execute "frm1.SubTotalsVAT.Value = FormatCurrency(TotalPriceVAT, 2, -1, 0, 0)"
Execute "frm1.Total.Value = FormatCurrency(TotalPrice, 2, -1, 0, 0)"
End If

Else
MsgBox "This is not a valid number!"
Execute "frm1.Qty("&i&").Value = 0"
End If


End Function






This is executed whenever the user enters a value in any one of the Qty fields:




Code:


<input type="text" name="Qty" size=5 language="VBScript" OnChange="Call CalcSubTotal(<%=strProductID%>,<%=strCurrency%>,<%=strUnitPrice%>,<%=strVAT%>,Me.Value)">






Now, I will probably have to rewrite this then in JavaScript as well? Does JavaScript have something similar to FormatCurrency? Or would I need to write a function that rounds to two decimals and then add the appropriate currency symbol?



Thanks in advance for your help!

Was this answer helpful ? Yes No   
Guest


Just found this



http://javascript.internet.com/form...ncy-format.html



It may be useful

Was this answer helpful ? Yes No   
Guest


Thanks! Seems like it could be working with a little bit of modification for the various currencies.

Was this answer helpful ? Yes No   
Guest
 
 
Home - About Infoqu - Contact - Privacy Statement - Link to Infoqu - Bookmark Infoqu

Copyright 2007-2008 by Infoqu. All rights reserved