I'm letting my users write their own HTML from my webpage.
When they click the preview button, my code behind needs access to controls on the page (and so I understand I can't use a web method here).
It builds the HTML and saves it as a file on the server.
My question is: Once the file has been made, I want to automatically open the file in a new window for the user to see their handy work.
I'm using vb.net, but happy to receive c# answers.
Thanks folks ! . .
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=--=-=-=--=-=- Thank you very much Jan !!
I still have a slight problem though...
My code goes like this:
If fileExists Then
Do Until fileExists = False
tmpFormPreviewFileName = "Test" & GetRandomNumber() & ".html"
tmpFormPreviewFilePath = Server.MapPath("~") & "Pages\FormPreviews\" & tmpFormPreviewFileName
fileExists = My.Computer.FileSystem.FileExists(tmpFormPreviewFileName)
Loop
End If
My.Computer.FileSystem.WriteAllText(tmpFormPreviewFilePath, strHTML, False)
'Now open the file in a new window
btnPreview.OnClientClick = String.Format("window.open('/Pages/FormPreviews/{0}', 'myPopup', 'width=400,height=500')", tmpFormPreviewFileName)
So, the problem is - I don't know what the filename will be until after the user has clicked the preview button and the OnClientClick event won't fire until the user clicks the button for the 2nd time (which of course creates another HTML file)
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=--=-=-=-=-=-=--=-=-=--=-=-=-=-=-=-=-=-=-=-=-=- I'm still having problems getting the popup to work. Here's my code at the moment:
'create a JavaScript command for opening the file in popup window
Dim strScript As String = String.Format("window.open('/Pages/FormPreviews/{0}, 'myPopup', 'width=400,height=500')", tmpFormPreviewFileName)
'register the JavaScript to be executed when web page loads
ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "openPopup", strScript, True)
ScriptManager.RegisterStartupScript(Me, Me.[GetType](), "ShowMsg", "javascript:alert('Test Msg');", True)
My "ShowMsg" fires succesfully, but the line above it (the popup code) doesn't seem to work. Can you see what's going wrong at all ?