2

I want to assign the html content to iframe control from asp.net code behind page;

this is working fine 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.

i want some thing like this(Ashok) to be displayed in iframe control

i tried the bellow ways but nothing is succesful

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

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

3 Answers 3

1

A way to communicate between two different pages where one is in an IFrame on the other, is to post data using JQuery. An example is given in this StackOverflow question

It is also discussed in this other StackOverflow question

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!).

Hope some of this helps!

Sign up to request clarification or add additional context in comments.

Comments

0

You can't. That's not how an IFRAME works - it is for use with the src attribute as you've already discovered.

Perhaps you want to create a DIV instead

1 Comment

This accepted answer is no longer correct. You can make an iframe show HTML by setting its srcdoc attribute: developer.mozilla.org/docs/Web/API/HTMLIFrameElement/srcdoc You can also set the src attribute to a data url containing the encoded HTML: developer.mozilla.org/docs/Web/HTTP/Basics_of_HTTP/Data_URLs
0

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,

or

You can create a page for example called getContent.aspx which request value from the URL e.g. getContent.aspx?content=<h1>Thank You..</h1> and display it wherever you like, and then call it from iframe.

1 Comment

If you want to send the content to another page in such a way though (and I'm not necessarily saying I would! ;) ), it would probably be better to use Post instead of a Get parameter for two reasons: You can Post more data than you can include with Get, and you will also make that data less visible to the client (ie. avoid "cluttering up" the URL of the page if someone should look at the source, or navigate directly to the inner page).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.