Search code examples
c#javascriptasp.netpage-lifecycleascx

Running Javascript to size an ASP.NET control once it is rendered or updated by a postback


I have an ascx control that is loaded in an aspx page. How can I instruct my ascx to run javascript once it is rendered in the browser. It should run on every postback as well.

I looked around but could not find a satisfactory answer.


Solution

  • Have you tried using the "RegisterStartupScript" method along with JQuery to call a JS function? This code might help you:

    ScriptManager.RegisterStartupScript(Page, GetType(Page), "myScript", "$(function() {{ alert ('Your page is loaded.'); }});", True)
    

    You can replace the alert with any JS function you want :)

    I hope this helps.