jquery - Error with Javascript on Partial Page Update -
i have scripts needs run when partial page changes. on 1st page load seems working fine after partial page updated javascript stopped working
1st try: tried put javascript in partial page not working
2nd try: tried put javascript on parent page partial page upadted
code load partial page:
@html.dropdownlist("usertype", directcast(viewbag.usertype, selectlist), new {.onchange = "changeusertype(this.value)"}) <div id="rendertreeview"> @html.partial("_treeview") </div> <script> function changeusertype(usertype) { $('#rendertreeview').load("/usermaster/changepermission?iusertypeid=" + usertype); } //and somme of other javascript function create tree view </script>
this script doesnot work on partial page update
<script> $(document).ready(function () { $('#check-all').click(function () { $("input:checkbox").attr('checked', true); }); $('#uncheck-all').click(function () { $("input:checkbox").attr('checked', false); }); }); $(document).ready(function () { $('.tree li').each(function () { if ($(this).children('ul').length > 0) { $(this).addclass('parent'); } }); $('.tree li.parent > a').click(function () { $(this).parent().toggleclass('active'); $(this).parent().children('ul').slidetoggle('fast'); }); $('#all').click(function () { $('.tree li').each(function () { $(this).toggleclass('active'); $(this).children('ul').slidetoggle('fast'); }); }); $('#add').change(function () { addpermission(); }); $('#change').change(function () { addpermission(); }); $('#delete').change(function () { addpermission(); }); $('#view').change(function () { addpermission(); }); $('#print').change(function () { addpermission(); }); }); function setpagenumber(pageid) { var pageid = document.getelementbyid("pageid"); pageid.value = pageid var permissionsofpage = document.getelementbyid(pageid).value var addcheck = permissionsofpage.charat(0); var changecheck = permissionsofpage.charat(1); var deletecheck = permissionsofpage.charat(2); var viewcheck = permissionsofpage.charat(3); var printcheck = permissionsofpage.charat(4); checkuncheckcheckboxes(addcheck, changecheck, deletecheck, viewcheck, printcheck) } function checkuncheckcheckboxes(addcheck, changecheck, deletecheck, viewcheck, printcheck) { //$('#permission input:checked').removeattr('checked'); if (addcheck == 1) { $('#add').attr('checked', true); } else { $('#add').removeattr('checked'); //$('#add').attr('checked', false); } if (changecheck == 1) { $("#change").attr("checked", true); } else { $("#change").attr("checked", false); } if (deletecheck == 1) { $("#delete").attr("checked", true); } else { $("#delete").attr("checked", false); } if (viewcheck == 1) { $("#view").attr("checked", true); } else { $("#view").attr("checked", false); } if (printcheck == 1) { $("#print").attr("checked", true); } else { $("#print").attr("checked", false); } } function addpermission() { var pageidpermission = document.getelementbyid("pageid").value; var permissions if ($("#add").is(":checked")) { permissions = "1" } else { permissions = "0" } if ($("#change").is(":checked")) { permissions = permissions += 1 } else { permissions = permissions += 0 } if ($("#delete").is(":checked")) { permissions = permissions += 1 } else { permissions = permissions += 0 } if ($("#view").is(":checked")) { permissions = permissions += 1 } else { permissions = permissions += 0 } if ($("#print").is(":checked")) { permissions = permissions += 1 } else { permissions = permissions += 0 } var toset = document.getelementbyid(pageidpermission) toset.value = permissions } </script>
this partial page
<link href="~/assets/css/treeview.css" rel="stylesheet" /> <div class="span6"> <div class="portlet box grey"> <div class="portlet-title"> <div class="caption"><i class="icon-sitemap"></i>page permission (@viewbag.pageno)</div> <div class="actions"> <a href="javascript:;" id="all" class="btn green"> toggle all</a> </div> </div> <div class="portlet-body fuelux"> <div class="tree"> <ul> <li> <a >first level</a> <ul> <li><a href="#" id="xyz" onclick="setpagenumber('page_2')">second level</a><input type="text" id="page_2" @*style="display:none"*@ value="00000" /></li> <li><a onclick ="setpagenumber('page_1')">second level</a><input type="text" id="page_1" @*style="display:none"*@ value="00000" /></li> <li><a>second level</a></li> </ul> </li> <li> <a>first level</a> <ul> <li> <a>second level</a> <ul> <li><a>third level</a></li> <li><a>third level</a></li> <li> <a>third level</a> <ul> <li><a>fourth level</a></li> <li><a>fourth level</a></li> <li> <a>fourth level</a> <ul> <li><a>fifth level</a></li> <li><a>fifth level</a></li> <li><a>fifth level</a></li> </ul> </li> </ul> </li> </ul> </li> <li><a>second level</a></li> </ul> </li> <li> <a>first level</a> <ul> <li><a>second level</a></li> <li><a>second level</a></li> </ul> </li> </ul> </div> </div> </div> </div> <div class="span2" id="permission"> <div class="portlet box grey"> <div class="portlet-title"> <div class="caption"><i class="icon-key"></i> rights</div> </div> <div class="portlet-body fuelux"> <div> <input type="checkbox" id="add" /> add </div> <div> <input type="checkbox" id="change" /> change </div> <div> <input type="checkbox" id="delete" /> delete </div> <div> <input type="checkbox" id="view" /> view </div> <div> <input type="checkbox" id="print"/> print </div> <div> <input type="text" id="pageid" @*style="display:none"*@ value="0" /> @* <button onclick="changecheckbox()">toggle</button>*@ </div> </div> </div> </div>
Comments
Post a Comment