在 asp.net 中打开的窗口中的 Server.MapPath

发布于 2025-01-04 05:11:06 字数 421 浏览 4 评论 0原文

我想在用户单击按钮时打开一个新的弹出窗口。但是我面临一个问题,如何基于 server.mapPath 打开一个新的弹出窗口? 这是我的编码

  StringBuilder sb = new StringBuilder();
        sb.Append("<script>");


        sb.Append("window.open(" + Server.MapPath("~/reportPreview.aspx") + ", '', '');");
        sb.Append("</script>");


        ClientScript.RegisterStartupScript(this.GetType(),"test", sb.ToString());

,但我无法打开新窗口。请帮忙:(

i want to open a new pop up window when user click the button.But nw i facing a problem, how can i open a new pop up window based on server.mapPath?
Here is my coding

  StringBuilder sb = new StringBuilder();
        sb.Append("<script>");


        sb.Append("window.open(" + Server.MapPath("~/reportPreview.aspx") + ", '', '');");
        sb.Append("</script>");


        ClientScript.RegisterStartupScript(this.GetType(),"test", sb.ToString());

But i cant open a new window . Please help :(

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

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

发布评论

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

评论(1

各自安好 2025-01-11 05:11:06

window.open 需要一个类似“../reportPreview.aspx”的 URL,但 Server.MapPath 返回类似“C:\YourApp\reportPreview.aspx”的物理路径。您应该改为调用 ResolveClientUrl。此外,您还需要在 URL 两边添加引号:

sb.Append("window.open('" + ResolveClientUrl("~/reportPreview.aspx") + "', '', '');"); 

window.open expects a URL like "../reportPreview.aspx", but Server.MapPath returns a physical path like "C:\YourApp\reportPreview.aspx". You should call ResolveClientUrl instead. Also, you need to add quotes around the URL:

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