UpdatePanel and Custom Server Control RegisterClientScriptBlock

I have an ajax UpdatePanel. In it there is a combobox on the right, when I click it, it is to update the panel on the left with one of two controls.

When the page initially loads, it loads the first control. When I click, it loads the second control. The second control contains a custom web server control that loads to javascript functions, using: RegisterClientScriptBlock

The page errors when I click to load the second control because the javascript has never been loaded in the page, although when I step through it, it does hit that code with no errors.

If I load the second control first, it does load the script fine.

It appears that loading the second control with ajax doesn't update the javascript as it should.

What are recommendations for getting this javascript loaded on this page. I have thought of putting the javascript for the control in a separate function and calling it on the main page that contains the two controls, however, that seems like a band-aid.

Is there a way to actually load it when the control is loaded that I am missing? Does ajax not support this?

Starr DuskkASP.NET VB.NET DeveloperAsked:
Who is Participating?
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I didn't get an answer that worked on this, but I rigged it to check which panel is  loading, and if the first, I register the script with the first panel, if the second, I register it with the second panel, that way I don't register it twice, but it gets registered either way.

In Asp.Net Ajax Page.ClientScript.RegisterClientScriptBlock will not work as expected during Asynchronous postback.

try replacing Page.ClientScript.RegisterClientScriptBlock with ScriptManager.RegisterClientScriptBlock
The example above is good, if you are looking to redirect the user when the session actually times out and not when they take an action after they timeout you can use the Timer control (included in .NET 3.5 available as an add-on for .NET 2.0 - ASP.NET AJAX).

Just set the interval to the session timeout and on the Tick event redirect to a timeout page.
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Sorry wrong question.
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
It says ScriptManager is not declared.
I have a reference and imports:

Imports System.Web.UI
Do you have reference for System.Web.Extensions.dll?

If you are able to use UpdatePanel then you should be able to use ScriptManager.  Both are there in the same assembly and namespace.
Starr DuskkASP.NET VB.NET DeveloperAuthor Commented:
I've referenced  and done:
Imports System.Web.Extensions
But it errors on the imports line, even though it's in the references.
It says it cannot be found or doesn't contain any public member.
The updatepanel is in my webform in the web site. The stuff I'm trying to register is in a custom server control in a separate project.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.