Reputation: 2742
Assume a string variable in code behind containing some HTML content such as
Dim str1 As String = "<h3>hello</h3><p>some paragraph</p><table><tr><td>some table content</td></tr></table>"
A saved file could be opened by registering a script such as
Dim script1 As String = "window.open('popupPage.html', 'myPopup')"
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "someId", script1, true)
Is there any way to output this content in a new tab or window from code behind without saving it to a file?
Upvotes: 1
Views: 304
Reputation: 58
You can pass an empty string for a file name
'Declare a script with your variable
Dim script1 As String = "<script>var popwin = window.open('','myPopup');popwin.document.write('" & str1 & "');</script>"
'Call your script with ScriptManager for async postback from UpdatePanel
ScriptManager.RegisterStartupScript(Me, Me.GetType(), "poptest", script1, true)
'Call your script with ClientScript for synchronous postback outside/without UpdatePanel
ClientScript.RegisterStartupScript(Me.GetType, "popuptest", script1, True)
check this Call javascript function from asp.net code behind after server side code executes
Upvotes: 1