Vinz' Blog

"Code, Beer and Music" ~ my way of being a programmer!
posts - 124, comments - 367, trackbacks - 0

My Links

News

Archives

Image Galleries

Creating an AJAX Enabled Webparts in Aspnet 2.0

Introduction:

Most of the web applications nowadays prefer to be an AJAX enabled application. Ajax enabled applications is basically eliminates those annoying flickers occurred when a page is refreshed.

This articles shows on how we are going make our webparts to be an ajax enabled one.

 

Below are the steps in creating an Ajax enabled application.

 

  1. Open Visual Studio 2005 and Create new Website
  2. Select ASP.NET AJAX-Enabled Web Site then press OK (See Figure A)

 

Figure A

 

  1. As what you have notice, the ScriptManager Control is automatically added to your page. ScriptManager handles the Ajax functionality like the WebPartManager.
  2. Drag Updatepanel control below the ScriptManager (See Figure B)

      

       Figure B

 

  1. Drag a WebPartManger inside the Updatepanel control
  2. Drag two WebPartZone below the WebPartManager (See Figure C)

        

        Figure C

 

  1. Drag a TextBox control in the WebpartZone
  2. Compile the Appication and Run the Website
  3. Drag a webpart in different zones and observe what happens

 

As what you have noticed, you can drag and drop a webpart only once and if you would try to drag it again it will just highlight the header of the webpart that you are trying to drag. Basically by default, webparts do not support updatepanel control but they provide a workaround on how to move webparts and supported in updatepanel control.

 

The Problem

ASP.NET Web Parts Drag and Drop feature and Drop down verbs menu does not operate correctly inside of a Microsoft AJAX 1.0 UpdatePanel.

           

Why it doesn't work?

The WebPartManager is responsible for registering an include and start up script. This script provides Web Parts and zones with various client side functionality including drag and drop and

drop down verb menus.

 

When a control is placed inside of an Update Panel, the script is rendered and ran on the first render, but not on subsequent renders. Due to this, the client side functionality fails.

 

The Workaround

The solution is simple. Inherit the WebPartManager, override the RenderClientScript Method and render the client scripts using the System.Web.UI.ScriptManager instead of the System.Web.UI.ClientScriptManager.

 

The System.Web.UI.ScriptManager informs Ajax of the registered client scripts and ensures that they are rendered out and executed whenever an UpdatePanel is refreshed. To achieve this, follow the steps below:

 

  1. Right click on the Project and Add a Reference (See Figure D)

Figure D

 

  1. Click the Add Reference. You should be able to see the add reference window.
  2. Click on the Browse Tab (See Figure E)

Figure E

 

  1. Browse the Sample.Web.UI.WebParts.dll file. You can download it at said Url below:

\\ Release – I attached the dll together with this file

  1. Add the following Tag Mapping to the specified section of your web.config:

<configuration>

           <system.web>

                        <pages>

                                    <tagMapping>

                                    <add tagType="System.Web.UI.WebControls.WebParts.WebPartManager"

                                    mappedTagType="Sample.Web.UI.WebParts.WebPartManager, Sample.Web.UI.WebParts"/>

                                    </tagMapping>

                        </pages>

            </system.web>

</configuration>

 

  1. Compile the Application and Run again.
  2. The result can be seen in the screen shot below:

 

Figure F

As what you have notice now, you can drag and drop webparts in different zones without flicker or without refreshes the entire page.

By: Vincent Maverick Durano

 

 

Print | posted on Monday, February 04, 2008 1:44 AM |

Feedback

Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

This is very informative. We are currently running into this problem. I wated to try your solution but the dll seems to be missing. Any chance you could put it back up? :)
5/9/2008 7:58 AM | Chantelle
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

Hi Chantelle,

Yes i forgot to update the link for downloading the dll file.. Anyways.. you can download the dll file in this link below...

http://www.koffeekoder.com/ArticleDetails.aspx?id=340_Creating_Ajax_Enabled_Webparts

Thanks...
5/12/2008 4:11 AM | Vinz
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

Hi,

I couldnt find the dll in the updated location too. It is showing a HTTP 404 error. Can you please make it available ?
We are currently running in to this problem.
6/3/2008 8:49 PM | VP Menon
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0


Hi Menon,

Koffeekoder has renewed that's why the link is not accessible anymore.. But you can download the dll in the GridViewGuy site.. see the link below

http://www.gridviewguy.com/Articles/340_Creating_Ajax_Enabled_Webparts.aspx

Thanks,
6/4/2008 1:16 AM | Vinz
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

Hi,

This is really nice article,

Thanks
11/13/2008 4:36 AM | Thanigainathan.S
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

its working fine from second time onwards but not first time.
3/2/2009 10:58 PM | swapna
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

Man, I saved tons of time with this article..Good Job.Keep it Up.
Thanks.
5/6/2009 8:06 PM | Jaschar
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

How to create the Ajax included webpage in .net2008 . am trying to open but only default web site are available there no other option for Ajax included webpage
5/27/2009 11:44 PM | Tamil
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

@Tamil,

AFAIK, AJAX Enable Web Site is already integrated in Visual Studio 2008 that's why it does not appear in the VS Templates. This means that you can make your site as AJAX in Enabled in VS 2008 by simply using the "AJAX Web Form". see this link for more info: http://weblogs.asp.net/palermo4/archive/2007/08/17/where-is-ajax-enabled-web-site-in-visual-studio-2008.aspx
5/28/2009 6:02 PM | Vinz
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

I already create asp.net web site. can i use ajax tools in my project or do i need to recreate my project in ajax enabled web site. i am using visual studio 2005. need help immediately. its better if you can send a answer to my email.

thanx
7/6/2009 5:08 AM | uditha
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

@ uditha,

You need to configure something in your web.config to make your site Ajax enabled.. see this link below for more info:

http://www.asp.net/AJAX/documentation/live/ConfiguringASPNETAJAX.aspx
7/6/2009 1:43 PM | Vinz
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

@ uditha, can u please give ur email address
9/7/2009 7:07 PM | Muhammad Liaquat
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

@ uditha, can u please give ur email address

email me at muhammad.liaquat @ gmail . com
9/7/2009 7:10 PM | Muhammad Liaquat
Gravatar

# re: Creating an AJAX Enabled Webparts in Aspnet 2.0

Why you need my mail add? If you wan't to ask questions then I would suggest you to post it here or post it at forums.asp.net
9/7/2009 7:37 PM | Vinz
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: