Reputation: 3293
I have 2 LinkButtons in my asp.net page. When I click on the first one, I want second one to be visible so I use the following code to achieve it:
LinkButtons:
<asp:LinkButton runat="server" id="LB1" OnClientClick="updateApplet(); return false;" Text="LB1" />
<asp:LinkButton runat="server" id="LB2" style="display: none;" Text="LB2" />
After some process done in updateApplet() function I want LB2 to become visible after everyhting is done. However asp page refreshes with no reason.
function updateApplet() {
var msg = document.capture.capture();
var hiddenControl = '<%= inpHide.ClientID %>';
document.getElementById(hiddenControl).value = msg;
document.getElementById('LB2').style.display = 'inherit';
// Without last line everything is perfect but I want LB2 is to be visible and this line refreshes my page :(
}
Can someone help me with my problem?
Upvotes: 1
Views: 128
Reputation: 10095
return false is missing in your Java Script function.
Java Script Code
function updateApplet() {
var msg = document.capture.capture();
var hiddenControl = '<%= inpHide.ClientID %>';
document.getElementById(hiddenControl).value = msg;
document.getElementById('LB2').style.display = 'block';
return false;
}
HTML Tag
<asp:LinkButton runat="server" id="LB1" OnClientClick="return updateApplet();"
Text="LB1" />
Upvotes: 1
Reputation: 6277
I think the reason for this is that
document.getElementById('LB2').style.display
crashes your page and the return false of the client click doesn't have chance to run so the page refreshes.
Try
document.getElementById('<%= LB2.ClientID %>').style.display = 'inherit'
Upvotes: 1
Reputation: 8667
Please check whether your updateApplet()
function completes normally (that is, there is no JavaScript exception thrown).
By the look of it, your last line causes a JavaScript error and then the return false;
statement isn't called, and so the default LinkButton's behavior is triggered.
EDIT: Yea, I've found it. Your second button's ID isn't LB2
, you should've done
document.getElementById('<%= LB2.ClientID %>').style.display = 'inherit';
Upvotes: 4