Home | Sample 1 | Sample 2

This Ajax sample tries integrating a static Javascript source file with dynamic controls on an ASP.NET AJAX page. The problem in this scenario is the user of a MultiView control which holds two views which each contain a user control. The user controls need to define variables that the static Javascript source file will use but when the page is first displayed only the first view is rendered. When I tried to to this initially I placed the variable declarations in the template part of the user controls but that was not being rendered at all for the second view. What I discovered does work is using the RegisterScriptBlock method under Page.Client script which is run for the user controls even when the content is not rendered. As a result all of the necessary variables work. And it also allows the user controls to work with and without the UpdatePanel which wraps the view and is used to provide the Ajax functionality.

This sample shows the MultiView working with and without the UpdatePanel. The date at the bottom shows how it does not change in the second page which is Ajax enabled. The TextBox and button call a static Javascript function which looks for the content block defined by the currently shown user control and replaces it with the contents of the TextBox. This shows that the static source file is able to successfully identify the block where the content will be replaced.

Below you can download this sample project.

[ Download Sample Project ]
Brennan Stehling - SmallSharpTools.com