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))
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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)
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0