RegisterStartupScript not working after upgrading to framework 3.5

Posted by AaronS on Stack Overflow See other posts from Stack Overflow or by AaronS
Published on 2010-04-27T17:08:27Z Indexed on 2010/04/27 19:03 UTC
Read the original article Hit count: 299

Filed under:
|
|
|

I'm trying to upgrade an asp.net c# web project from framework 2.0 to 3.5.

When I do this, the client side script that gets written using RegisterStartupScript isn't rendered on the client page.

This works perfectly when I compile for 2.0, and for 3.0, but not when I compile for 3.5.

Here is the code that isn't getting rendered:

Page myPage = (Page)HttpContext.Current.Handler;
ScriptManager.RegisterStartupScript(myPage, myPage.GetType(), "alertscript", "alert('test');", true);

This is called from a class project, and not the web project itself, which is why I'm using the HttpContext.Current.Handler.

There are no errors getting generated from the compiler, the CLR, and there are no client side JavaScript errors.

If I do a search for the "alertscript" in my rendered page, the above code actually isn't there.

Anyone have ideas as to what is going on?

-Edit-

This seems to be an issue when I'm trying to register the script from an external project.

If I use the exact same code in a class file in the web project (not the code behind), it works. However, if I make a call to a method in a class from another project, it does not work.

Does the ScriptManager.RegisterStartupScript not get registered correctly if performed from somewhere besides the web project itself?

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#