怎么动态创建HTML文件,从代码背后创建动态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”大火成功地,但它(弹出代码)上面的线似乎并没有工作。你能看到有什么问题吗?

2012-05-23

wotney

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值