I have read many articles that talked about adding the Script
Manager to the SharePoint manually; that you have to go to the master page of
your SharePoint page, and then write a script manager tag to the HTML code
manually!
Actually, I do not prefer this way. As a developer, I would
like to add it dynamically by the code.
Go back to Listing 1 and take a look on OnInit
subroutine. Here we will add the script manager dynamically. We are checking if
there is an existing script manager on the page. If it is not, then we will create
a new script manager and we will add it in the page controls.
Dealing with UpdatePanel and UpdateProgress
If you try to add controls to UpdatePanel programmatically,
you will notice that the UpdatePanel requires you to add server controls only.
So you need to choose the proper server control that matches your requirement
after rendering time. For example, if you want to add HTML div inside the UpdatePanel,
you should add the panel control instead of the HTML div element.
Since the UpdateProgress control is a template control, you
have to create a template class that represents the container of the
UpdateProgress controls. Listing 1 contains a public class called ProgressTemplate, I have created an instance from that
class in CreateChildControls subroutine and then I
have added the loading animation image inside the UpdateProgress using that instance.
To make our Ajax webpart more reusable, there is a public
property called LoadingImageURL which enables you to
set path of the loading animation image. So you can upload the image you want
into your Sharepoint site, and then you can use it as loading image by using LoadingImageURL public property.