开发者

Why is my javascript parameter giving me a "It may be inaccessible due to a protection level." error?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜