locked
onload event for DIV RRS feed

  • Question

  • User469998836 posted

     Hello everyone,

    I have a div inside an update panel and I want to execute a JavaScript code every-time a post-back happens inside the update panel.

    I have tried the onload event, but, it doesn't seem to work.

     

    Best Regards,

    Girish.

    Monday, April 20, 2009 2:42 AM

Answers

  • User-1429188810 posted

     Why don't you just call the Client-side function from the server side as soon as it executes the code after a postback...

     ScriptManager.RegisterStartupScript(this, this.GetType(), "foo", "foo()", true);

    You can even pass parameters to that function from here.....

     The above one is to execute a specific function on a specific Update panel update, but if you need to fire a javascript function after every update panel update, then do something like this...

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(foo);

    Hope it helps. Mark as Answer if it does.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 22, 2009 4:07 PM

All replies

  • User-18289217 posted

     I guess you should indentify what control has triggered the event and then execute your javascript.

    Btw, UpdatePanel works its magic by converting postbacks into asynchronous callbacks (XML-HTTP requests) and using JavaScript on the client to refresh the part of the page encapsulated by the UpdatePanel control. PageRequestManager manages the asynchronous callbacks launched by UpdatePanel. It’s also responsible for updating the content inside an UpdatePanel when an asynchronous callback completes.

    There is the Sys.WebForms.PageRequestManager class in the Microsoft AJAX Library that manages the asynchronous callbacks launched by UpdatePanel. It’s also responsible for updating the content inside an UpdatePanel when an asynchronous callback completes.

    PageRequestManager fires events in the browser before and after an update occurs. You can hook these events in JavaScript and run code that draws a user’s attention to the updated content. The key event is named pageLoaded. This event fires each time the page loads in the browser (it’s analogous to Page_Load in ASP.NET). It also fires each time an asynchronous callback launched on behalf of an UpdatePanel control completes and the content inside that UpdatePanel is updated. You can register a JavaScript handler for the pageLoaded event with two lines of code (which can be combined into one):


     
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    prm.add_pageLoaded(pageLoaded);
     

     

    The first line acquires a reference to the page’s PageRequestManager object. The second registers a JavaScript function named pageLoaded as a handler for pageLoaded events.
    When called, a pageLoaded event handler receives an argument of type Sys.WebForms.PageLoadedEventArgs, which is another class in the Microsoft AJAX Library. PageLoadedEventArgs contains a get_panelsUpdated method that you can call to enumerate all the UpdatePanels, if any, whose content was just updated. By default, an UpdatePanel is nothing more than a DIV on the client-side so you can use JavaScript to flash the DIV, highlight it, or do whatever you want to do to draw a user’s attention to it.
    Monday, April 20, 2009 3:48 AM
  • User469998836 posted

    var prm = Sys.WebForms.PageRequestManager.getInstance(); prm.add_pageLoaded(pageLoaded);
     

    Hi Kulrom,

    Your post probably suffices my need. In my case:

    prm.add_pageLoaded(pageLoaded);

     pageLoaded is a parameterized function. Where do I pass the parameters, in this case?

     

    Thanks,

    Girish.

    Monday, April 20, 2009 6:09 AM
  • User-18289217 posted

    This event fires each time the page loads in the browser (it’s analogous to Page_Load in ASP.NET).

     

     

    I  would try this avoiding parametrized Load event. In this way you can still call the pageLoaded in a way i suggested.

     
    Private Sub DoSomething(byval myparam As String)
       ' Do something
    End Sub
    
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
       DoSomething(value)  
    End Sub 
      
    Monday, April 20, 2009 7:13 AM
  • User469998836 posted

     I am trying to execute a javascript code. Not the cs code.

    Wednesday, April 22, 2009 10:27 AM
  • User-18289217 posted

     well that's the same. Just remove the parameters to another function and then call this function from the Load event.

    Wednesday, April 22, 2009 12:11 PM
  • User469998836 posted

    I think I am not quite clear about this concept. Can please explain it to me? (Its very urgent!)..

     

    Thanks,

    Girish.

    Wednesday, April 22, 2009 2:33 PM
  • User-1429188810 posted

     Why don't you just call the Client-side function from the server side as soon as it executes the code after a postback...

     ScriptManager.RegisterStartupScript(this, this.GetType(), "foo", "foo()", true);

    You can even pass parameters to that function from here.....

     The above one is to execute a specific function on a specific Update panel update, but if you need to fire a javascript function after every update panel update, then do something like this...

    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(foo);

    Hope it helps. Mark as Answer if it does.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 22, 2009 4:07 PM