in my asp.net application I have a page That has two iframes. Above these frames are a few link buttons. When these buttons are hit, they should change the src of the two iframes. Listed below is the client side code and javascript I am using to do this. The issue is when any of these buttons are hit, instead of just changing the src of one of the iframes, the whole page refreshes. (i can tell this is refreshing because the link buttons are not available till you log in on the first page shown in the main frame, after you log in the buttons become visible via a call to the parent – window.parent.loginSuccess() ). If one of them is then clicked, it sends you back to the log in page in the iframe and the buttons are are no longer visible.) Here is the code, does anyone see why this is happening? Thank you for your help.
<body id="bodysty">
<div id="fstyle" class="daform">
<form id="form1" runat="server">
<div id="master">
<div id="topthing"> <asp:LinkButton ID="lbtnControlPanel" onclientclick="CPhit()" runat="server" style="display:none">Control Panel</asp:LinkButton> <asp:LinkButton ID="lbtnAddClient" runat="server" onclientclick="AddClientHit()" style="display:none">Add Client</asp:LinkButton> <asp:LinkButton ID="lbtnManageClients" runat="server" onclientclick="ManageClientsHit()" style="display:none">Manage Clients</asp:LinkButton> <asp:LinkButton ID="lbtnAdmin" runat="server" onclientclick="ManageClientsHit()" style="display:none">Admin Options</asp:LinkButton></div>
<div id="leftcontrol">
<iframe id="LeftIframe" runat="server" ></iframe>
</div>
<div id="mainbodyform">
<iframe id="ContentIframe" runat="server" src="Login.aspx" class="mainiframe" ></iframe>
</div>
</div>
</form>
</div>
</body>
</html>
<script language="javascript">
function CPhit() {
document.getElementById("ContentIframe").src = "LoginNotes.aspx";
}
function AddClientHit() {
document.getElementById("ContentIframe").src = "NewCustomer.aspx";
}
function loginSuccess() {
document.getElementById('lbtnControlPanel').style.display = 'inherit'
document.getElementById('lbtnAddClient').style.display = 'inherit'
document.getElementById('lbtnManageClients').style.display = 'inherit'
document.getElementById('lbtnAdmin').style.display = 'inherit'
}
</script>
There is no code in the codebehind that deals with this page, its simply for navigation. Any ideas? Thank you for your help.
You need to cancel the default click action of the item you are clicking on.
Simple way is to return false on the click event.
better way is preventDefault()