views:

17

answers:

0

I converted a .NET 2.0 application in VS 2005 to a .NET 4.0 application in VS 2010 and am experiencing an issue registering a script to run after the page has been fully loaded. I am using the following vb.net code to register a javascript function. This vb.net code is called in the OnPreRender of a custom server control that only gets loaded on postback (I use a "tab-like" control and a multiview to show different detail screens). In .NET 2.0 this works just fine, but not in .NET 4.0.

Dim js As String = "Sys.Application.add_load(function() { " + _
            "AddressInputSetState('" + Me.ClientID + "');" + _
            "});"
        Page.ClientScript.RegisterStartupScript(Me.GetType(), Me.ClientID + "_init", js, True)

In my search for an answer, I learned that the Sys.Application.add_load method is designed to register a javascript function that will only run when the web page first loads. Is this correct? If so, it is odd that the javascript function would ever run since the function is registered on a postback.

This is code that I inherited so I don't fully understand the reasons behind when the javascript function is registered. However, I attempted to register the AddressInputSetState script as a startup script, but I get errors due to some controls not having been fully rendered yet (AJAX issue?)