Tuesday, 20 August 2013

Simple .Show function not displaying DIV on page load

Simple .Show function not displaying DIV on page load

I have a check box on my page "cbxShowNotifications." If it is checked
when the page loads, I want to SHOW "treeview."
.aspx page:
<html>
<body>
<form>
<asp:CheckBox ID="cbxShowNotifications" runat="server"/>Show
Notifications
<div id="treeview"></div>
</form>
<script src="../Scripts/jquery.min.js" type="text/javascript">
</script>
<script src="../Scripts/kendo.web.min.js" type="text/javascript">
</script>
<script src="../Scripts/NotificationsTreeView.js"
type="text/javascript"> </script>
<script type="text/javascript">
$(document).ready(function()
{
showOrHide();
});
</script>
<script type="text/javascript">
$(document).ready(function()
{
CreateNotificationTree(<%=
UserId.ToString(CultureInfo.InvariantCulture) %>);
});
</script>
</body>
</html>
JavaScript file:
function CreateNotificationTree(userId)
{
var data = new kendo.data.HierarchicalDataSource({
transport: {
read: {
url: "../api/notifications/byuserid/" + userId,
contentType: "application/json"
}
},
schema: {
model: {
children: "notifications"
}
}
});
$("#treeview").kendoTreeView({
dataSource: data,
loadOnDemand: true,
dataUrlField: "LinksTo",
checkboxes: {
checkChildren: true
},
dataTextField: ["notificationType", "NotificationDesc"],
select: treeviewSelect
});
function treeviewSelect(e)
{
var node = this.dataItem(e.node);
window.open(node.NotificationLink, "_self");
}
}
$('#cbxShowNotifications').on('change', function()
{
debugger;
var tview = $('#treeview');
if ($(this).prop('checked'))
{
tview.show();
}
else
{
tview.hide();
}
});
function showOrHide()
{
debugger;
var tview = $('#treeview');
if ($(this).prop('checked'))
{
tview.show();
}
else
{
tview.hide();
}
}
The problem is, when the page loads AND the check box is checked, the
treeview is NOT visible. What am I doing wrong?
By the way, after the page is loaded, if I uncheck the checkbox, the tree
disappears and if I check it, it appears.
So this is only happening at page load which leads me to believe it's an
issue of WHEN things are being executed.

No comments:

Post a Comment