为什么我的 javascript 参数给我一个“由于保护级别,它可能无法访问。”错误?
我的代码
<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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您正试图将 JavaScript 变量传递给 VB 方法。不幸的是,这不起作用,因为在执行 JavaScript 时页面已经被解析并输出到浏览器(已经离开服务器)。
一种选择是通过使用 ajax 检索该值。
如果你已经有了隐藏字段的值,你可以做这样的事情吗?
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?
您正在服务器标记内引用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.