简体   繁体   English

文件后面的代码的HTML弹出窗口

[英]Html popup window from code behind file

This could be a simple but I havent found any easy solution. 这可能很简单,但我还没有找到任何简单的解决方案。

On clicking button in asp.net web page on button click event html is generated from xml and xsl. 在单击按钮时,单击asp.net网页中的按钮时,将根据xml和xsl生成事件html。 This html is stored as string variable. 该html存储为字符串变量。 For example lets say 例如说

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

From the above html string how can I dynamically create html popup window in vb.net. 从上面的html字符串中,如何在vb.net中动态创建html弹出窗口。 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 我可以使用javascript在前端创建弹出窗口,但是还没有找到通过vb.net文件后面的代码创建弹出窗口的任何解决方案

Edit: 编辑:

This does not work in IE, only works in firefox: 这在IE中不起作用,仅在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)) 

You can only create a popup-window with javascript, so you need to register that script from codebehind: 您只能使用javascript创建弹出窗口,因此您需要从代码隐藏中注册该脚本:

ClientScript.RegisterStartupScript(Me.GetType(), "newWindow", String.Format("<script>window.open('{0}');</script>", 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? 您不仅要从代码隐藏中打开客户端弹出窗口( window.open ),而且要在没有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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM