简体   繁体   English

如何从asp.net代码背后将HTML内容分配给iframe控件?

[英]How to assign HTML content to iframe control from asp.net codebehind?

I want to assign the html content to iframe control from asp.net code behind page; 我想从页面后面的asp.net代码将html内容分配给iframe控件;

this is working fine myIframe.Attributes.Add("src", "pathtofilewith.html"); 这工作正常myIframe.Attributes.Add(“ src”,“ pathtofilewith.html”); but, i don't want to give the path of html file to display i just want to assign some html content which comes from database to iframe control. 但是,我不想提供要显示的html文件的路径,我只想分配一些来自数据库的html内容到iframe控件。

i want some thing like this(Ashok) to be displayed in iframe control 我希望在iframe控件中显示诸如此类的内容(Ashok)

i tried the bellow ways but nothing is succesful 我尝试了下面的方法,但是没有成功

myIframe.Attributes["innerHTML"] = "<h1>Thank You..</h1>";

myIframe.Attributes.Add("innerHTML", "<h1>Ashok</h1>");

A way to communicate between two different pages where one is in an IFrame on the other, is to post data using JQuery. 在一个页面位于另一个IFrame中的两个不同页面之间进行通信的一种方法是使用JQuery发布数据。 An example is given in this StackOverflow question 此StackOverflow问题中给出了一个示例

It is also discussed in this other StackOverflow question 另一个StackOverflow问题中对此进行了讨论

On this page , you will also find a short and simple example of how you can put content in an IFrame without using a separate web-page for it (note the lacking src attribute!). 此页面上 ,您还将找到一个简短的示例,说明如何在不使用单独网页的情况下将内容放入IFrame中(请注意缺少src属性!)。

Hope some of this helps! 希望有些帮助!

You can't. 你不能 That's not how an IFRAME works - it is for use with the src attribute as you've already discovered. 这不是IFRAME工作原理-它已与您已经发现的src属性一起使用。

Perhaps you want to create a DIV instead 也许您想创建一个DIV

There is no way to insert HTML content into iframe tag directly, but you can create a page which gets the content form the database and then you can view it using iframe , 无法将HTML内容直接插入到iframe代码中,但是您可以创建一个从数据库获取内容的页面,然后可以使用iframe查看它。

or 要么

You can create a page for example called getContent.aspx which request value from the URL eg getContent.aspx?content= <h1>Thank You..</h1> and display it wherever you like, and then call it from iframe . 您可以创建一个名为getContent.aspx的页面,该页面从URL请求值,例如getContent.aspx?content = <h1>Thank You..</h1>并显示在任意位置,然后从iframe调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM