我让我的用户从我的网页上编写自己的HTML。
当他们点击预览按钮时,我的代码需要访问页面上的控件(所以我知道我不能在这里使用web方法)。
它构建HTML并将其作为文件保存在服务器上。
我的问题是:
文件制作完成后,我想在新窗口中自动打开文件,以便用户查看其便捷的工作。
我正在使用vb.net,但很高兴收到c#的答案。
谢谢大家!
。
- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -
非常感谢Jan !!
我仍然有一个小问题...
我的代码是这样的:
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)
所以,问题是 - 在用户点击预览按钮之前我不知道文件名是什么,OnClientClick事件直到用户第二次点击按钮才会触发(当然会创建另一个HTML文件)
- = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = - = -
我仍然无法让弹出窗口工作。
这是我目前的代码:
'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)
我的“ShowMsg”成功触发,但它上面的行(弹出代码)似乎不起作用。你能看出出了什么问题吗?