Reputation: 22076
I have an iframe
in my main aspx
page and this iframe
has also a aspx
page. iframe's page has some controls and main aspx page has a submit button on it. Now I want to postback
iframe's page on submit button's click event using javascript
. So that main page remain static and iframe's page goes for a postback
UPDATE
Thanks @Kevin Babcock and @Bala R
Suppose if I need to perform a button (which is in iframe) click event through main page
Upvotes: 9
Views: 12785
Reputation: 1
Every Browser Supported
window.frames[0].document.getElementById('btnSave').click();
or
window.frames['iframename'].document.getElementById('btnSave').click();
Upvotes: 0
Reputation: 31
In the parent page(Parent.aspx page) contains one iframe page(FrameChild.aspx page), when you need we need to call a method of iframe button event, then we have to follow like this.
In the parent page javascript method call like this:
<script type="text/javascript" language="javascript">
function functionName() {
document.getElementById(iframeID).contentWindow.MyIFrameFunction();
}
iframeID is the frame id, MyIFrameFunction() is the name of javascript function in the FrameChild.aspx, and call the functionName() method through the button of parent page, which inturn call the below MyIFrameFunction() of the child .js function.
In the child page(FrameChild.aspx) should contain one function.
<script type="text/javascript" language="javascript">
function MyIFrameFunction() {
__doPostBack('btnRenew', 'passparameter');
}
</script>
assume one button in FrameChild.aspx.
<asp:Button ID="btnRenew" runat="server" OnClick="btnRenew_Click" />
code behind of 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) { }
The above code work for me.
Upvotes: 3
Reputation: 19392
Add a button to your page and call it something like ID="btn_ParentSubmit".
Let's say you named your iframe ID="iframeTest"
In your Page_Load() add this:
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;"
}
Upvotes: 0
Reputation: 10247
Try the following:
window.frames[0].document.forms[0].submit();
This assumes the following things:
Upvotes: 1
Reputation: 108937
From javascript you can try something like
document.frames["iframeid"].document.forms[0].submit();
Upvotes: 4