How to send aspx page in iframe?

I have an iframe on my aspx main page, and this iframe also has an aspx page. There are some controls on the iframe page, and there is a submit button on the aspx main page. Now I want a postback iframe page when sending a button click event using javascript . So the main page remains static and the iframe page is for postback
UPDATE
Thanks @Kevin Babcock and @Bala R
Suppose if I need to execute a button (which is in an iframe), click the event through the main page

+8
javascript html iframe
source share
5 answers

From javascript you can try something like

 document.frames["iframeid"].document.forms[0].submit(); 
+4
source share

The parent page (Parent.aspx page) contains one iframe page (FrameChild.aspx page), when you need to call the iframe button's event method, then we should follow as follows.

In the parent page, the javascript method calls the following:

 <script type="text/javascript" language="javascript"> function functionName() { document.getElementById(iframeID).contentWindow.MyIFrameFunction(); } 

iframeID is the frame identifier, MyIFrameFunction () is the name of the javascript function in FrameChild.aspx and calls the functionName () method using the parent page button, which calls the call below MyIFrameFunction () of the child element. js.

The child page (FrameChild.aspx) must contain one function.

 <script type="text/javascript" language="javascript"> function MyIFrameFunction() { __doPostBack('btnRenew', 'passparameter'); } </script> 

suppose one button in FrameChild.aspx.

 <asp:Button ID="btnRenew" runat="server" OnClick="btnRenew_Click" /> 

behind the FrameChild.aspx page.

 protected void Page_Load(object sender, System.EventArgs e) { string target = Request["__EVENTTARGET"]; //btnRenew string paremeter = Request["__EVENTARGUMENT"]; //passparameter if (!string.IsNullOrEmpty(target) && !string.IsNullOrEmpty(arg)) { btnRenew_Click(sender, e); } } public void btnRenew_Click(object sender, EventArgs e) { } 

This code works for me.

+3
source share

Try the following:

 window.frames[0].document.forms[0].submit(); 

This implies the following things:

  • you don't have several iframes on your page (if so, you need to specify the correct one in the frames array)
  • you do not have multiple forms in your iframe (if so, you need to reference the correct one in the forms array)
  • the page loaded in the iframe is loaded from one domain, port and protocol (otherwise you will not be able to access the contents of the iframe due to browser security).
+1
source share

Add a button to your page and name it as ID = " btn_ParentSubmit ".
Say you called your iframe ID = " iframeTest "
In Page_Load (), add the following:

 if (IsPostBack == false) { //Either place the button in an UpdatePanel (so it won't reload the iFrame) -OR- add "return false;" to prevent the post-back and let the iFrame submit itself. - 09/25/2012 - MCR. btn_ParentSubmit.OnClientClick = "javascript:document.getElementById('" + iframeTest.ClientID + "').contentDocument.forms[0].submit(); return false;" } 
0
source share

Every browser supported

  window.frames[0].document.getElementById('btnSave').click(); 

or

  window.frames['iframename'].document.getElementById('btnSave').click(); 
0
source share

All Articles