In my asp.net application i have a page that has two iframes, and the main page being displayed inside this iframe contains a button. When this button is hit, it calls a javascript function which takes part of the URL and calls a javascript function in the parent window. When the function from the parent is hit, it should change the src of the iframe to a different page – this is not happening. The main iframe has an id ContentIframe and the side iframe has an id LeftIframe. When this is hit – the left side iframe src is changed to nothing, and this works because the left side display does not show what was previously there. The call to change the iframe src for the content frame happens, and the codebehind even loads ( i am able to tell by placing tracepoints in the pageload in the code behind) – but the page is never displayed in the iframe, the previous page with the origional button we clicked is still being displayed. Does anyone know why this would happen? Heres my code
The button
<asp:Button ID="btnEditClient" onclientclick="editClient();" runat="server" Text="Edit Client Info" />
editClient javascript function
function editClient() {
var location = window.location.href;
var idindex = location.indexOf("clientid");
idindex = idindex + 9;
var id = location.slice(idindex, location.length);
window.parent.redir('client', id);
}
redir parent javascript function
function redir(type, id) {
if (type = 'client') {
document.getElementById('ContentIframe').src = "NewCustomer.aspx?clientid=" + id;
document.getElementById('LeftIframe').src = "";
}
}
If I were to add the following line below the LeftIframe src change above
document.getElementById('ContentIframe').disabled = true;
The ContentIframe will not show at all. Also as stated above, the pageload for the NewCustomer.aspx page is hit as I could tell by using breakpoints. Thanks again!
edit – after the call to change the src, looking at the developer tools, here is the form in the iframe, still says the previous pages items – not sure if this will help or not – maybe the method=post may have to do with this?
<form id="form1" action="NewClientSummary.aspx?clientid=13" method="post">
The problem is that
<asp:Button>is rendered as a submit button. This means that clicking it will submit the form and the form in the frame is probably directed to the same page. (default action)Either use ordinary button:
Or if you need it server side, just cancel the default action of the button by returning false: