My code
<script type="text/javascript" language="javascript">
function jsFullPath(relPath) {
var hidefield开发者_如何学JAVA = document.getElementById('HiddenField1');
hidefield.value = relPath;
var fullPathStr = '<%= fullPath(hidefield.value) %>';
}
</script>
Public Function fullpath(ByVal relPath As String) As String
Dim fullPathStr As String = Server.MapPath(relPath)
Return fullPathStr
End Function
Everytime I compile I get that error. I don't understand why. It should work.
It looks as if you are trying to pass a JavaScript variable to your VB method. This unfortunately will not work, as the page has already been parsed and output to the browser (already left the server) by the time your JavaScript is being executed.
One option would be to retrieve this value through the use of ajax.
If you already have the value of the hidden field, can you do something like this?
<script type="text/javascript" language="javascript">
function jsFullPath() {
return '<%= Server.MapPath('HiddenField1.Value') %>';
}
</script>
You are referencing hidefield (a JavaScript object) inside of a server tag. The exception is essentially telling you that hidefield is not defined on the server.
For this to work, the fullpath method needs to be invoked via Ajax.
精彩评论