Search code examples
javascriptasp.netonloadpageload

Add OnLoad() in Page_Load()?


I have a few Database things to read in the Page_Load of my Asp.net page.

if (xxx == 1)
  //Add OnLoad("clock()")

How to do this? How to add a OnLoad-Method for a JavaScript clock in the page load method?


Solution

  • 1st Make your body tag a servercontrol

    <body runat="server" id="BodyTag">
    

    2nd reference it like

    if (xxx == 1)  
      BodyTag.Attributes.Add("onload", "clock()");