从代码隐藏更改 IFrames InnerHtml

发布于 2024-08-02 02:28:00 字数 1631 浏览 3 评论 0原文

我正在尝试在运行时从后面的代码设置 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

妳是的陽光 2024-08-09 02:28:00

你可以试试这个:

protected void btnChange_Click(object sender, EventArgs e)
{
   myIframe.Attributes["src"] = "pathtofilewith.html"
}

或者也许这也有用:

protected void btnChange_Click(object sender, EventArgs e)
{
   myIframe.Attributes["innerHTML"] = "htmlgoeshere"
}

You can try this:

protected void btnChange_Click(object sender, EventArgs e)
{
   myIframe.Attributes["src"] = "pathtofilewith.html"
}

or maybe this will work too:

protected void btnChange_Click(object sender, EventArgs e)
{
   myIframe.Attributes["innerHTML"] = "htmlgoeshere"
}
豆芽 2024-08-09 02:28:00

iFrame 没有innerHTML 属性。 但是,从 HTML 5.0 开始,出现了一个新的 srcdoc 属性。 http://www.w3schools.com/tags/tag_iframe.asp

值:HTML_code

描述:指定要在

中显示的页面的 HTML 内容。 iframe>

你可以这样使用:

protected void btnChange_Click(object sender, EventArgs e)
{
    myIframe.Attributes["srcdoc"] = "<h1>Contents Changed</h1>";
}

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

Value: HTML_code

Description: Specifies the HTML content of the page to show in the < iframe >

Which you could use like this:

protected void btnChange_Click(object sender, EventArgs e)
{
    myIframe.Attributes["srcdoc"] = "<h1>Contents Changed</h1>";
}
緦唸λ蓇 2024-08-09 02:28:00

您无法更改 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.

十级心震 2024-08-09 02:28:00
<asp:Button ID="btnChange" runat="server" Text="Change iframe content" onclick="btnChange_Click" />
<br />
<asp:Literal id="myIframe" runat="server" />

in the code behind:

protected void btnChange_Click(object sender, EventArgs e){
    myIframe.Text = "<h1>Contents Changed</h1>";
}
<asp:Button ID="btnChange" runat="server" Text="Change iframe content" onclick="btnChange_Click" />
<br />
<asp:Literal id="myIframe" runat="server" />

in the code behind:

protected void btnChange_Click(object sender, EventArgs e){
    myIframe.Text = "<h1>Contents Changed</h1>";
}
口干舌燥 2024-08-09 02:28:00

您需要做的是创建一个单独的 aspx 页面,该页面是空的,并获取响应并将其加载到自己的主体中,换句话说,替换自身,如

mypage.aspx:

<%@ Page contentType="text/html" %>
//... using your namespace that contains the required functionality
<% Response.Write(MyObject.CreateBody()) %>

然后将该页面放入您的 iframe 中...

<iframe src="mypage.aspx" ... />

简单地说, 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:

<%@ Page contentType="text/html" %>
//... using your namespace that contains the required functionality
<% Response.Write(MyObject.CreateBody()) %>

then place that page inside ur iframe...

<iframe src="mypage.aspx" ... />

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文