views:

448

answers:

2

Hi all, I have a webpage with one iframe and a button.

On Page Load event,

if (!Page.IsPostBack)
{
string sDocUrl = //some doucmen url
Iframe1.Attributes["src"] = sDocUrl;
}

When the page is reloaded (by clicking a button), this iframe is being reloaded too. This iframe has a static data and doesn't need to be reloaded everytime when I click a button. Is there a way to prevent iframe to be reloaded when webform is reloaded?

+1  A: 

When a page is reloaded, any iframes contained in it (just as any scrips, images, anything) will always be reloaded. There's no working around that, sorry, simply because the entire page actually reloads.

David Hedlund
A: 

You could add the iframe dynamically using JavaScript:

if (!Page.IsPostBack)
{
    $('#foo').append('<iframe src="' + sDocUrl + '"></iframe>');
}

That uses jQuery to add the iframe to an element with an id of "foo". But it will only add the iframe if the expression in the 'if' statement returns true.

Darrell Brogdon
Although on second glance at your question it seems you still want to have the iframe displayed on postback right? If thats the case then @d is correct, there is no way to prevent it from reloading.
Darrell Brogdon
Thanks, yes you are right, it needs to be there after post back too. Thanks for your help.
Dave