ASP.Net VB 从代码隐藏中调用 JavaScript 函数
我有一个负责填充 SSRS 报告的函数。用户按下按钮,我出去检查是否有数据。如果没有数据,我会提供“无数据”消息。如果有数据,我会调用 SSRS 报告,并希望在新窗口中打开该报告。我认为使用 JavaScript 函数是实现这一目标的最佳方法。这是如何完成的或者你会推荐什么?提前致谢!
<script type="text/javascript">
function openWindow(url) {
document.forms[0].target = "_blank";
}
</script>
I have a function that is responsible for populating an SSRS report. The user presses a button and I go out and check to see if there is data. If no data, I provide a NO DATA message. If there is data I call the SSRS report which I would like to open in a new window. I thought using a JavaScript function would be the best way to accomplish this. How is this done or what would you recommend? Thanks in advance!
<script type="text/javascript">
function openWindow(url) {
document.forms[0].target = "_blank";
}
</script>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
试试这个:
Try this:
请考虑使用
ClientScriptManager.RegisterClientScriptBlock
方法。它是一个静态方法,应该在您的页面上可用。使用示例如下:
当然,您可以将您在代码中准备好的任何网址放在后面...
希望它有所帮助。
Please consider using
ClientScriptManager.RegisterClientScriptBlock
method. It's a static method and should be avaible on your page.Example of usage is following:
Of course you can put any url that you have prepared in your code behind...
Hope it helps.
这里要记住一点:当您的 vb 代码运行时,浏览器中的页面并不存在。
请记住,网络通过 http 协议工作,而 http 协议可归结为请求和响应。始终先发出请求,然后才是响应。通常,响应是 html,这就是您的 vb 代码的用武之地。所有代码和 aspx 标记的唯一目的是让您的 Web 服务器可以将 html 发送回浏览器。浏览器和您的服务器之间没有活动连接。当您的 vb 代码运行时,浏览器中的网页并不真正存在(您的代码正忙于创建它)。当你的javascript运行时,用于在服务器上创建它的vb资源早已被回收。
Something to keep in mind here: while your vb code is running, the page in your browser doesn't exist.
Remember that the web works via the http protocol, and the http protocol boils down to requests and responses. Always a request first, followed by a response. Often, the response is html, and this is where your vb code comes in. The sole purpose of all the code and aspx markup is so that your web server can send html back to the browser. There is no active connection between the browser and your server. While your vb code is running, the web page in your browser doesn't really exist (your code is busy creating it). While your javascript is running, and vb resources used to create it on the server have long since been recycled.
如果您尝试根据服务器端逻辑的某些结果在页面上执行 javascript,实现此目的的一种方法是使用 asp 文字控件(或其他类型的 asp 控件)
示例:
然后只需在您的基于您的其他逻辑的服务器代码。
If you are trying to execute javascript on a page depending on some results of server side logic, one way you could achieve this is by using asp literal controls (or other types of asp controls)
Example:
Then just show or hide this literal in your server code based on your other logic.