从代码隐藏更改 IFrames InnerHtml
我正在尝试在运行时从后面的代码设置 Iframe 的 HTML。
在我的 aspx 页面中,我有:
<asp:Button ID="btnChange" runat="server" Text="Change iframe content"
onclick="btnChange_Click" />
<br />
<iframe id="myIframe" runat="server" />
在后面的代码中:
protected void btnChange_Click(object sender, EventArgs e)
{
myIframe.InnerHtml = "<h1>Contents Changed</h1>";
}
当我运行这个....它会回发,但根本不会更改 myIframe 内容... 我究竟做错了什么??
我需要这样做,因为我在结帐流程中实施了 3D 安全。 基本上:
1)客户输入信用卡详细信息 2) 提交表单,检查支付网关是否需要 3d secure。 如果是这样,则会生成 url 供银行安全位置输入信息 3) 我创建一个对此 url 的 POST 请求,其中包含一个长安全令牌和一些其他信息。 我获取从此 POST 请求返回的 HTML,并且需要在 iFrame 中显示它。
以下是文档所说的操作:
<html>
<head>
<title>Please Authenticate</title>
</head>
<body onload="OnLoadEvent();">
<form name="downloadForm" action="https://mybank.com/vbyv/verify" method="POST">
<input type="hidden" name="PaReq" value="AAABBBBCCCCHHHHHH=">
<input type="hidden" name="TermUrl" value="https:// www. MyWidgits.Com/next.cgi">
<input type="hidden" name="MD" value="200304012012a">
</form>
<script language="Javascript"> <!-- function OnLoadEvent(){ document.downloadForm.target = "ACSframe"; document.downloadForm.submit(); } //--> </script>
<!-- MERCHANT TO FILL IN THEIR OWN BRANDING HERE -->
<iframe src="blank.htm" name="ACSframe" width="390" height="450" frameborder="0">
</iframe>
<!-- MERCHANT TO FILL IN THEIR OWN BRANDING HERE -->
</body>
</html>
I'm trying to set the HTML of an Iframe at runtime, from code behind.
In my aspx page i have:
<asp:Button ID="btnChange" runat="server" Text="Change iframe content"
onclick="btnChange_Click" />
<br />
<iframe id="myIframe" runat="server" />
in the code behind:
protected void btnChange_Click(object sender, EventArgs e)
{
myIframe.InnerHtml = "<h1>Contents Changed</h1>";
}
When i run this.... it posts back, but doesn't change the myIframe contents at all...
What am i doing wrong??
I need to do this because im implementing 3D secure into my checkout process..
basically:
1) customer enters credit card details
2) form is submitted, checks with payment gateway if 3d secure is required. if so, url is generated for the banks secure location to enter information
3) i create a POST request to this url, that contains a long security token, and a few other bits of information. i get hold of the HTML returned from this POST request, and need to display it in an iFrame.
Heres what the documentation says to do:
<html>
<head>
<title>Please Authenticate</title>
</head>
<body onload="OnLoadEvent();">
<form name="downloadForm" action="https://mybank.com/vbyv/verify" method="POST">
<input type="hidden" name="PaReq" value="AAABBBBCCCCHHHHHH=">
<input type="hidden" name="TermUrl" value="https:// www. MyWidgits.Com/next.cgi">
<input type="hidden" name="MD" value="200304012012a">
</form>
<script language="Javascript"> <!-- function OnLoadEvent(){ document.downloadForm.target = "ACSframe"; document.downloadForm.submit(); } //--> </script>
<!-- MERCHANT TO FILL IN THEIR OWN BRANDING HERE -->
<iframe src="blank.htm" name="ACSframe" width="390" height="450" frameborder="0">
</iframe>
<!-- MERCHANT TO FILL IN THEIR OWN BRANDING HERE -->
</body>
</html>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
你可以试试这个:
或者也许这也有用:
You can try this:
or maybe this will work too:
iFrame 没有innerHTML 属性。 但是,从 HTML 5.0 开始,出现了一个新的 srcdoc 属性。 http://www.w3schools.com/tags/tag_iframe.asp
你可以这样使用:
There's no innerHTML attribute for an iFrame. However, since HTML 5.0, there's a new srcdoc attribute. http://www.w3schools.com/tags/tag_iframe.asp
Which you could use like this:
您无法更改 iframe insideHTML 属性。 它根本没有innerHTML 属性。 尝试 RegisterStartupScript 并使用 document.write 来更改 iframe 的内容,因为它是一个窗口。
顺便说一句,我认为 HTML 标签更适合这样做。
You can not change iframe innerHTML property. It does not have innerHTML property at all. Try to RegisterStartupScript and use document.write to change the content of the iframe since it is a window.
By the way, i think HTML tag is better place for this.
您需要做的是创建一个单独的 aspx 页面,该页面是空的,并获取响应并将其加载到自己的主体中,换句话说,替换自身,如
mypage.aspx:
然后将该页面放入您的 iframe 中...
简单地说, iframe 是一个客户端窗口,您无法从服务器端将其主体作为对象引用,它尚未加载!
或者...您可以打开一个 html 文件,转储响应,然后保存并关闭...该文件始终由您的 iframe 引用。 使用文本流对象,或文件系统对象等...
PS。 我还没有尝试过
what you need to do is create a seperate aspx page that is empty and that gets the response and loads it in its own body, in other words replace itself, like
mypage.aspx:
then place that page inside ur iframe...
simply put, the iframe is a client side window, you cannot reference its body as an object from the server side, it hasnt been loaded yet!
OR... you can open an html file, dump the response then save and close... that file is referenced by your iframe always. use Text stream objects, or filesystemobject or the like...
PS. i haven't tried any of it