为什么我的 javascript 参数给我一个“由于保护级别,它可能无法访问。”错误?

发布于 2024-11-08 21:54:21 字数 532 浏览 0 评论 0原文

我的代码

<script type="text/javascript" language="javascript">
        function jsFullPath(relPath) {
            var hidefield = 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

每次编译时都会出现该错误。我不明白为什么。它应该有效。

My code

<script type="text/javascript" language="javascript">
        function jsFullPath(relPath) {
            var hidefield = 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乱世争霸 2024-11-15 21:54:21

看起来您正试图将 JavaScript 变量传递给 VB 方法。不幸的是,这不起作用,因为在执行 JavaScript 时页面已经被解析并输出到浏览器(已经离开服务器)。

一种选择是通过使用 ajax 检索该值。

如果你已经有了隐藏字段的值,你可以做这样的事情吗?

<script type="text/javascript" language="javascript">
        function jsFullPath() {
            return '<%= Server.MapPath('HiddenField1.Value') %>';
        }
</script>

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>
以往的大感动 2024-11-15 21:54:21

您正在服务器标记内引用hidefield(JavaScript 对象)。该异常本质上是告诉您服务器上未定义 hidefield。

为此,需要通过 Ajax 调用 fullpath 方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文