Load content inside iframe with ajax

I have an iframe that works on the server side:

<iframe frameborder="0" runat="server" style="width: 100%; height: 700px; background-color: #bacad3;" id="I1" name="I1" src="Page.aspx"></iframe> 

and dynamically change the content using this code:

 protected void Button1_Click(object sender, EventArgs e) { I1.Attributes["src"] = "Page.aspx"; } 

I want to implement it using ajax as follows:

  • when the user clicks on the iframe side, does not leave a back page and changes the src iframe
  • I want to show progress inside progressupdatepanel

I mention that I don't want to trigger any postback, just loading the page inside the iframe using ajax, calling outside the iframe, for example, there is a button on the page, and it is processed by the refresh panel and loads the contents of another page inside the iframe. Can anyone help me out?

+4
source share
2 answers

With onClientClick and mmke, make sure you return false to cancel the postback.

 window.frames["frameName"].src = "http://example.com"; //or document.getElementById("iframeId").src = "http://example.com"; 

If you use runat = server, you may need a client id

 document.getElementById("<%= iframeId.ClientID %>").src = "http://example.com"; 
+3
source

I found out that this is not possible using this method, you cannot delete the postback, it needs a proxy method such as google mail (gmail), when you click Inbox, it appears on the right without postback, but we can’t implement this method.

0
source

All Articles