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?
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.
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.
精彩评论