从代码隐藏文件的Html弹出窗口 [英] Html popup window from code behind file

查看:138
本文介绍了从代码隐藏文件的Html弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在单击按钮时单击事件html是从xml生成的XSL。这个html被存储为字符串变量。例如,让我们说

  dim htmlString as string =< div>这是我的弹出窗口< / div> 

从上面的html字符串我怎样才能动态地在vb.net中创建html弹出窗口。我可以通过使用JavaScript在前端创建弹出窗口,但没有找到任何解决方案,通过vb.net文件后面的代码创建它。



编辑:



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

  Dim popupScriptScript As String = _ 
< script language ='javascript'> myPopup()< / script>
尺寸的MyString = LT; HTML><主体>< DIV风格= 的颜色:黑色 >名称:詹姆斯的< / DIV>< / BODY>< / HTML> 中
Page.ClientScript.RegisterStartupScript(Me.GetType(),PopupScript,String.Format(popupScript))


解决方案

你只能用javascript创建一个弹出窗口,所以你需要从代码隐藏中注册该脚本:

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

也许我错误地理解了你的要求。您不仅希望从代码隐藏中打开客户端弹出窗口( window.open ),还可以在不使用url的情况下即时创建该窗口?



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

  Dim popupHtml =< html>< body> < div style =color:black>名称: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)


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. This html is stored as string variable. 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. 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

Edit:

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)) 

解决方案

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))

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弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆