html动态创建html文件,从后面的代码创建动态html文件,并在新窗口中打开

博主正尝试在VB.NET应用中实现一个功能,允许用户编写HTML并在预览按钮被点击后自动生成文件。遇到的问题是文件名在用户点击前未知,导致无法在客户端的OnClientClick事件中正确打开新窗口预览。尝试通过注册JavaScript来解决,但目前弹出窗口未按预期工作。已展示部分代码片段寻求帮助。
摘要由CSDN通过智能技术生成

我让我的用户从我的网页上编写自己的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”成功触发,但它上面的行(弹出代码)似乎不起作用。你能看出出了什么问题吗?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值