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?
-Edit2-
To add more to this, I did the following:
- Registered an alert script from my web project class
- Called a method in an external class and simply registered another alert script
- Registered another alert script from my web project class
After all this is done, if I view the variable: myPage.ClientScript._registeredClientStartupScripts from the web project, I do see these three new entries, one for each of the scripts I just registered. So, I believe everything was added properly.
However, when I let the page finish executing and I look at the results in fiddler, I only see the two that were actually registered from the web project itself, and the one from the external class never makes it down.
Keep in mind, this all works perfectly fine in frameworks 2.0 and 3.0, just not in 3.5.