Assuming that you set the panel visibility on the server side, checking the value returned document.getElementById()will work if you make sure that you use the correct control panel client identifier (don) t hard code).
See client side validation findPanel()for a demonstration.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function findPanel() {
var panel = document.getElementById("<%= pnlMyPanel.ClientID %>");
if (panel) {
alert("Panel is visible");
}
else {
alert("Panel is not visible");
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel runat="server" ID="pnlMyPanel">
<p>
This is a panel.</p>
</asp:Panel>
<asp:Button runat="server" ID="btnToggle" Text="Toggle panel visibility..." />
<input type="button" value="Do client-side visibility check..." onclick="javascript:findPanel();" />
</div>
</form>
</body>
</html>
The following code in a code-encoded file switches the panel visibility when clicked btnToggle:
protected void Page_Load(object sender, EventArgs e)
{
btnToggle.Click += new EventHandler(btnToggle_Click);
}
void btnToggle_Click(object sender, EventArgs e)
{
pnlMyPanel.Visible = !pnlMyPanel.Visible;
}
source
share