来自文件后面代码的 Html 弹出窗口

Html popup window from code behind file(来自文件后面代码的 Html 弹出窗口)
本文介绍了来自文件后面代码的 Html 弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能很简单,但我还没有找到任何简单的解决方案.

This could be a simple but I havent found any easy solution.

在 asp.net 网页中单击按钮单击事件 html 是从 xml 和 xsl 生成的.此 html 存储为字符串变量.例如让我们说

On clicking button in asp.net web page on button click event html is generated from xml and xsl. This html is stored as string variable. For example lets say

dim htmlString as string = "<div>This is my popup</div>"

从上面的 html 字符串如何在 vb.net 中动态创建 html 弹出窗口.我可以使用 javascript 在前端创建弹出窗口,但还没有找到通过 vb.net 中的代码隐藏文件创建它的任何解决方案

From the above html string how can I dynamically create html popup window in vb.net. I can create popup window on front end by using javascript but havent found any solution to create it through code behind file in vb.net

这在 IE 中不起作用,只在 firefox 中起作用:

This does not work in IE, only works in firefox:

Dim popupScript As String = _
   "<script language='javascript'> myPopup() </script>" 
Dim mystring = "<html><body><div style=""color:black"">Name: Jame's</div></body></html>" 
Page.ClientScript.RegisterStartupScript(Me.GetType(), "PopupScript", String.Format(popupScript)) 

推荐答案

你只能用javascript创建一个弹出窗口,所以你需要从codebehind注册那个脚本:

You can only create a popup-window with javascript, so you need to register that script from codebehind:

ClientScript.RegisterStartupScript(Me.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", url))

也许我误解了你的要求.您不仅想从代码隐藏中打开客户端弹出窗口(window.open),还想在没有 url 的情况下即时创建该窗口?

Maybe i've misunderstood your requirement. You want not only to open a client-side popup(window.open) from codebehind but also create that window on the fly without url?

也许这有帮助(未经测试):

Maybe this helps(untested):

Dim popupHtml = "<html><body><div style=""color:black"">Name: Jame's</div></body></html>"
Dim openPopupScript = "NewPopup=window.open("", 'newWindow', 'height=250, width=250');" & _
                      "NewPopup.document.open();" & _
                       String.Format("NewPopup.document.write('{0}');", popupHtml) & _
                      "NewPopup.document.close();"
ClientScript.RegisterStartupScript(Me.GetType(), _
                      "newWindow", _
                      openPopupScript)

这篇关于来自文件后面代码的 Html 弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
quot;Overflowquot; compiler error with -9223372036854775808L(编译器错误-9223372036854775808L(Q;溢出Q))
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)