I'm integrating JQuery functionality into my ASP.net application. And some wrote some functionality with JQuery. Along with that I'm coding ASP.Net by integrating AJAX control toolkit, to make my JQuery work with updatepanel, i wrapped my code in requestmanger endrequest as (sample) following.
<script type="text/javascript">
var requestManager = Sys.WebForms.PageRequestManager.getInstance(); requestManager.add_endRequest(function () { var listboxdiv = $("div.listBoxdiv");$(".spanclose").on("click", function () { listboxdiv.fadeOut(); }); }); </script>
I'm wrapping this in script block after <form> tag declaration.
To make this functionality work on page load, i'm wrapping same code in <head> as following
<script type="text/javascript"> $(function () { var listboxdiv = $("div.listBoxdiv");$(".spanclose").on("click", function () { listboxdiv.fadeOut(); }); });</script>
I know, i'm repeating code. but i sent to production and everyone happy
but i want to know how to achieve this with out repeating
Thanking you in advance.