0

I'm looking to call a jQuery function after the page has loaded completely for the post back (after pressing a button).
Can anyone please tell me how to do that.
Tried this, but with no luck:

 $("#<%= btnOK.ClientID %>").click(function (e) {
      window.onload = function () {
           $("#<%=UIGridViewUserTaskSearchResults.ClientID%>").tablesorter();
             JqueryFunction();
       }    
 });
Himanshu
  • 4,327
  • 16
  • 31
  • 39
Knowledge2Share
  • 103
  • 1
  • 2
  • 14
  • possible duplicate of [Do something AFTER the page has loaded completely](http://stackoverflow.com/questions/9036969/do-something-after-the-page-has-loaded-completely) – richardgirges Jun 09 '15 at 15:03

2 Answers2

0

Switch it around. Try this:

$(document).ready(function()
{
    $("#<%= btnOK.ClientID %>").click(function (e)
    {
        $("#<%=UIGridViewUserTaskSearchResults.ClientID%>").tablesorter();
    });
});
Lance
  • 3,824
  • 4
  • 21
  • 29
  • I'm getting this error:: JavaScript runtime error: Unable to get property 'xxx' of undefined or null reference.. I have to call my JQuery function after my page loaded completely.. but it seems it is not happening in that way... – Knowledge2Share Jun 09 '15 at 15:45
  • 1
    The code I gave you will do that. I believe the error is in your php. Perhaps you can post a View Source of your page so we can see what the php is actually doing. – Lance Jun 09 '15 at 15:48
  • 1
    This ain"t PHP but ASP.NET/VB.NET/Whatever .NET you want. Just looking the `<% SOMETHING %>` is enough to deduce so. In PHP, it's ``. – Bladepianist Jun 12 '15 at 07:44
0

If you bind any jQuery handler to an ASP.Net button click, when you click the button, first the handler will fire, then the page will be immediately reloaded by postback. If you wish to run a jQuery code after postback, you need to put that in $(document).ready() event, and then make sure this "ready" is fired after postback.

You can achieve this by setting a Hidden Field value from server side code on Button_Click handler, then check the value of that hidden field in jQuery $(document).ready() event. There will be no $("#<%= btnOK.ClientID %>").click handler.

Rocker1985
  • 312
  • 1
  • 7