Here is the code snippet I am working with:
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequestHandle);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(endRequestHandle);
function beginRequestHandle(sender, Args) {
//Perform actions when call begins.
document.getElementById("btn1").style.visibility = "hidden";
document.getElementById("btn2").style.visibility = "hidden";
}
function endRequestHandle(sender, Args) {
if (document.getElementById('<%= hfResultsCount.ClientID %>').value != 0) {
document.getElementById("btn1").style.visibility = "visible";
document.getElementById("btn2").style.visibility = "visible";
}
else {
document.getElementById("results").innerHTML = "<br><b><center><font style='font-family:Haettenschweiler; font-size:xx-large'>No data found, please try again.</b></font></center>";
}
}
</script>
Additionally, here is the code for btn2:
<input type="button" runat="server" name="btn2" id="btn2" value="New Window"
style="visibility:hidden;font-weight:bold;width:200" onclick="window.open('http://microsoft.com');" />
I am using JavaScript to show/hide buttons, and while it works for asp:button
, I encounter an error with <input type=button>
:
Microsoft JScript runtime error: Unable to get value of the property 'style': object is null or undefined
I managed to resolve this issue for btn1
by adding ClientID=Static
. How can I achieve the same for the <input>
button without converting it to asp:button?
Everything is enclosed in an UpdatePanel with ClientID=Static. The problem seems to be related to IDs and the master page, as it functions properly on individual pages.