January 2008 - Posts

My ex-buddy Tanzim Saqib has wrote an excellent article on creating controls in Volta. Really worth to check it out.



I am proud to announce the final release of v1.0 of AjaxDataControls. The v1.0 has a lot of enhancements and bug fixes, which I have mentioned in my previous post, the whole API is now available in CHM format. The Latest sample also has few cool demo of Ajax Control Toolkit integration. Checkout the following screenshots:

Integrating with Calendar Extender:

Integrating with MaskEdit Extender:

Integrating with NumericUpDown and  FilteredTextBox Extender:

You can download the latest version from the CodePlex release tab.

I would love to see your comments and feedbacks.

kick it on DotNetKicks.com

In my previous post, I have shown how to do data binding, data sorting and different type of columns of AjaxDataControls GridView. In this post, I will show how to enable Drag and Drop of the GridView Columns and automatically persist it with the help of Ajax Profile Service.

The GridView internally uses the preview version of Asp.net Ajax Drag and Drop script for the column Drag and Drop. So the first thing you have to do is to add these scripts in your script manager, the GridView also uses the animation script (PreviewGlitz.js) to do the animation when binding with data, So I would also recommend to add this script to exploit the full feature of  GridView.

<asp:ScriptManager ID="TheScriptManager" runat="server">
    <Services>
        <asp:ServiceReference Path="~/DataService.asmx" />
    </Services>
    <Scripts>
        <asp:ScriptReference Path="~/PreviewScripts/PreviewScript.js" />
        <asp:ScriptReference Path="~/PreviewScripts/PreviewDragDrop.js" />
        <asp:ScriptReference Path="~/PreviewScripts/PreviewGlitz.js" />
    </Scripts>
</asp:ScriptManager>

By default the GridView turns on the drag and drop for all type of columns except Button, Command and Radio columns. But you can also allow Drag and Drop for those column types by setting the AllowDragAndDrop property to true of the individual columns. Now, lets take quick example of the GridView, here we will see the Suppliers of the Northwind database. The following shows the control declaration in the aspx page:

<AjaxData:GridView ID="GridView1" runat="server" CssClass="DataWebControlStyle">
   <AlternatingRowStyle CssClass="AlternatingRowStyle" />
   <RowStyle CssClass="RowStyle"/>
   <HeaderStyle CssClass="HeaderStyle"/>
   <Columns>
    <AjaxData:GridViewBoundColumn HeaderText="Company" DataField="Company"/>
    <AjaxData:GridViewBoundColumn HeaderText="Contact" DataField="ContactName"/>
    <AjaxData:GridViewBoundColumn HeaderText="Title" DataField="ContactTitle"/>
   </Columns>
</AjaxData:GridView>

As you can see we are doing nothing special except adding the preview scripts in the script manager. Next, add the following JavaScript codes in your aspx page:

<script type="text/javascript">

    var _gridView;

    function pageLoad(sender, e)
    {
        _gridView = $find('<%= GridView1.ClientID %>');
        loadSuppliers();
    }

    function loadSuppliers()
    {
        DataService.GetAllSupplier(onLoadSuccess);
    }

    function onLoadSuccess(result)
    {
        _gridView.set_dataSource(result);
        _gridView.dataBind();
    }

</script>

Once done, run it, you will able to do the drag and drop like the following:

As you can see it gives some cool drag and drop abilities of the columns, but once you refresh the page the GridView appears same as it appears for the first time, which means the Drag and Drop of the columns has not been persisted. To add the persistence support we have to do the following things:

  • Configure the Asp.net Profile Provider.
  • Configure the Ajax Profile Services to allow access the Profile Object. Click here if you need to know how to configure the Ajax Profile Service. 
  • Few modification in the control declaration and javascript code.

For the shake of this example I have add the Asp.net Provider support in the Northwind database and added the following settings in the web.config file:

<anonymousIdentification enabled="true"/>
<membership defaultProvider="SqlMemberShipProvider" userIsOnlineTimeWindow="1">
  <providers>
    <clear/>
    <add name="SqlMemberShipProvider" applicationName="Northwind" connectionStringName="NorthwindConnectionString" type="System.Web.Security.SqlMembershipProvider"/>
  </providers>
</membership>
<profile defaultProvider="SqlProfileProvider">
  <providers>
    <clear/>
    <add name="SqlProfileProvider" applicationName="Northwind" connectionStringName="NorthwindConnectionString" type="System.Web.Profile.SqlProfileProvider"/>
  </providers>
  <properties>
    <add name="DndColumns" type="System.String" provider="SqlProfileProvider" allowAnonymous="true"/>
  </properties>
</profile>
</system.web>
<system.web.extensions>
<scripting>
    <webServices>
        <profileService enabled="true" readAccessProperties="DndColumns" writeAccessProperties="DndColumns"/>
    </webServices>
</scripting>
</system.web.extensions>

As you can see, in the profile provider I have added a property named DndColumns which type is string. You can name it anything but the type needs to be string. Next, I gave both read/write permission of this property to Ajax Profile Service. Now we have to change the previous javascript code and the control to load and persist the columns. The following shows control, the modifications are in bold:

<AjaxData:GridView ID="GridView1" runat="server" CssClass="DataWebControlStyle" ColumnsLoadedFromProfileEvent="onColumnsLoaded" ColumnDroppedEvent="onColumnDropped">
   <AlternatingRowStyle CssClass="AlternatingRowStyle" />
   <RowStyle CssClass="RowStyle"/>
   <HeaderStyle CssClass="HeaderStyle"/>
   <Columns>
    <AjaxData:GridViewBoundColumn HeaderText="Company" DataField="Company"/>
    <AjaxData:GridViewBoundColumn HeaderText="Contact" DataField="ContactName"/>
    <AjaxData:GridViewBoundColumn HeaderText="Title" DataField="ContactTitle"/>
   </Columns>
</AjaxData:GridView>

In the new declaration, I have added two new client side events, the control will fire the onColumnsLoaded function when the grid completes the column loading from the asp.net profile and it will also fire the onColumnsDropped function when a column is dropped. And the following shows the modified code for the client side:

<script type="text/javascript">

    var _gridView;

    function pageLoad(sender, e)
    {
        _gridView = $find('<%= GridView1.ClientID %>');
        _gridView.loadColumnsFromProfile('DndColumns');
    }

    function onColumnsLoaded(sender, e)
    {
        loadSuppliers();
    }

    function loadSuppliers()
    {
        DataService.GetAllSupplier(onLoadSuccess);
    }

    function onLoadSuccess(result)
    {
        _gridView.set_dataSource(result);
        _gridView.dataBind();
    }

    function onColumnDropped(sender, e)
    {
        _gridView.saveColumnsToProfile('DndColumns');
    }

</script>

As you can see, here in the pageLoad event (which automatically fired by the Asp.net Ajax Framework) we are instructing the GridView to load the columns from the previously configured Profile property DndColumns. Once the columns are loaded, the GridView fires the onColumnLoaded function where we are loading the suppliers and when a column is dropped the onColumDropped function gets executed where we are storing the newly ordered columns in the Profile. Now when you refresh the page or re visit the page you will find it persisted.

You will find the full working demo in the Sample folder of the CodePlex Release tab.

kick it on DotNetKicks.com

I have recently started writing a multi-part series article on AJAX Control Toolkit. Throughout the series I will cover the following items:

Explore
  • Input Helpers - FilteredTextBox and NumericUpDown.
  • Input Helpers - MaskEdit and Slider.
  • Input Helpers - CascadingDropDown and Calendar.
  • Input Helpers - ToggleButton, Rating and ValidatorCallout.
  • Containers - Dynamic Populate and CollapsiblePanel.
  • Containers -Tabs.
  • Containers - Accordion.
  • Popups - Popup, DropDown and ModalPopup.
  • Others- NotBot and PasswordStrength.
  • Others- ToolkitScriptManager.
Architecture
  • Core Framework
  • Animation Framework
Build
  • Demonstrate how to develop a first class control on top of Ajax Control Toolkit.

The introductory part explores a few basic input helpers.

I would love to see your comments and feedbacks.

kick it on DotNetKicks.com

A short summary for them who are wondering about my MVP award and my contributions to the .NET Community:

Open Source Projects:

  1. Asp.net Ajax Data Controls  - Super Hit!!!
  2. Asp.net Ajax Exception Logging

Articles:

  1. Asp.net Ajax Grid and Pager
  2. Asp.net Ajax Control Development
  3. Asp.net Ajax Repeater
  4. Asp.net Ajax Exception Logging
  5. Asp.net Ajax Web Service- Common Issues

Book Reviews:

  1. Asp.net AJAX in Action
  2. Asp.net AJAX Update Panel Control

Blog Posts:

  1. Cross Domain Iframe Resize
  2. Secure Url
  3. Secure Cookie
  4. Utilize ThreadPool in WebService
  5. Performance Benchmark with an Handy Class
  6. Check User Name in Ajax way
  7. SJAX Call
  8. Cancel a Web Service Call in Asp.net Ajax
  9. Asp.net Ajax and VS2003
  10. Combine Multiple JavaScript and CSS Files and Remove Overheads
  11. Implement Yahoo's YSlow in your Asp.net pages
  12. Create An Ajax Style File Upload
  13. Asp.net Ajax UpdatePanel Simultaneous Update - A Remedy
  14. Loading UserControl Dynamically in UpdatePanel
  15. Showing Modal Progress Dialog in all Ajax Operation
  16. Asp.net ListView - Too much CSS Friendly
  17. Asp.net ListView - DataBinding
  18. Asp.net ListView - Data Editing
  19. Compress Asp.net Ajax Web Service Response - Save Bandwidth
  20. New Project - Asp.net Ajax Exception Logging
  21. Asp.net Ajax Web Service Security
  22. Asynchronous Asp.net Page ( Do not Follow it ever)
  23. Implement JSONP in your Asp.net Application
  24. AjaxDataControls - Beta Released
  25. AjaxDataControls GridView Part One

Forums:

  1. Asp.net Ajax Forum : Solved around 200 issues.
  2. DotNetSlackers forum : Active member.

If you are from Bangladesh, India and I think also from Nepal and want to become MVP. I would suggest:

  1. Do some massive community work both online and offline like writing books or may be articles, participating in forums, newsgroup, blogging, creating few open source projects etc whatever that really helps the community.
  2. Both Microsoft Employees and existing MVPs can nominate you. If your think your contribution is extraordinary and if you know any of them, you can ask to nominate you. Or
  3. You can download a nomination form for South Asia region and nominate yourself.

The MVP award is announced every quarter and is based on previous year's contribution. If your name is not announced, wait for the next quarter and increase your community activity and apply again. The bottom line is you are helping the community with your exemplary contribution thus making the people life successful.

I am proud to announce that I have been awarded as MVP in Visual Asp/Asp.net for 2008.

"Dear Kazi Rashid, Congratulations! We are pleased to present you with the 2008 Microsoft® MVP Award! The MVP Award is our way of saying thank you for promoting the spirit of community and enhancing people’s lives and the industry’s success every day. Your extraordinary efforts in Visual Developer - ASP/ASP.NET technical communities during the past year are greatly appreciated. "

Since it is my first award, I am very much excited and hoping my contribution to the community will continue like this.

More Posts