May 10 2007

Multiple Selection in ListBox

Category:Bil@l @ 10:57

Every time you want to have a multiple selection in a List Box, you have to write the same repetitive code again and again. Here is a nice utility method that you can embed into your web applications and use it by a simple method call to select multiple items inside a List Box:

 

/// <summary>
/// Selects multiple items in a ListBox control
/// </summary>
/// <remarks>
/// This method starts by validationt the two input parameters:
/// 1. <paramref name="lst" />
/// 2. <paramref name="items" />
/// The first parameter is the <see cref="System.Web.UI.WebControls.ListBox"/> whose elements
/// are to be selected. The second parameter is simply an array of <see cref="System.String"/>s
/// that represent the items that are to be selected inside the <paramref name="lst" />.
/// </remarks>
/// <param name="lst">ListBox to select its items</param>
/// <param name="items">Array of <see cref="System.String" />s</param>
private void SelectMultipleItems(ListBox lst, string[] items)
{
 // Loop through the items of the array containing
 // items to be selected
 for(int i=0; i<items.Length; i++)
 {
  // Loop through the items inside the listbox
  // break whenever you find the item serching for
  foreach(ListItem lt in lst.Items)
  {
   // compare the item coming from the array
   // to the one coming from the listbox
   if (lt.Value == items[ i ])
   {
    lt.Selected = true;
    break;
   }
  }
 }
}

 

Hope this helps,
Regards

Tags:

May 6 2007

ValidationSummary Control and RadWindow by Telerik

Category: Telerik ControlsBil@l @ 11:57

I have recently been heavily using Telerik great controls, that I admire and respect, in my projects at work. I have decided to customize every single control in our applications that Telerik provides a substitution for. The RadWindow is a very cool control that I have started using it as a substitution for the usual JavaScript Open or ShowModaldialog methods.


A nice feature that I wanted to customize is the ValidationSummary alert box. As you know, when you place a ValidationSummary control on a page, you can enable it to show a popup alert box listing all the errors on the page. Check out the figure below to see the current behavior of the ValidationSummary with an alert box:

What would be nice is to show a RadWindow instead of that old-fashioned alert box. Before we start writing any code, it is nice to Google a bit and see if any colleague developer has already customized the ValidationSummary so that not to re invent  the wheel. I was able to find a nice article on the CodeProject website written by Jeff Shantz that you can reach at: http://www.codeproject.com/aspnet/vsum.asp

Before going on in this article I recommend you go to the above URL and read that article. It explains to you what you should add to the WebValidationUI.js file so that the ValidationSummary can show a Modal or normal Popup window.
I have followed the same steps as mentioned in the above article and added a small property to the ValidationSummar control which is the windowname. The windowname property holds the name of the RadWindow that is already added to the RadWindowManager on the ASPX page. The validation summary to place on your ASPX page now is as follows:


            <asp:validationsummary id="vsmSummary" runat="server" ForeColor="DarkRed" showcustompopup="True" customurl="Msgbox.aspx"
                customwidth="308" customheight="270" customheader="Attention!" customtitle="Error on Form" modal="False"
       windowname="ValidationSummary" ShowSummary="False" ShowMessageBox="false"></asp:validationsummary>

Notice the underlined and bold property above. We have added a custom property to the ValidationSummary control to specify the RadWindow name to show the errors in.

What you also need to add to the ASPX page is the following RadWindowManager:


            <radw:radwindowmanager id="RadWindowManager1" runat="server" Behavior="Close,Move" Skin="Blue" Modal="True">
    <Windows>
     <radw:RadWindow Height="270px" SkinsPath="~/RadControls/Window/Skins" ID="ValidationSummary" Width="308px"
      Skin="Default" Left="" NavigateUrl="" VisibleStatusbar="False" Modal="True" Top="" Title=""></radw:RadWindow>
    </Windows>
   </radw:radwindowmanager>

In addition you need to update the WebValidationUI.js file located under the framework version inside the aspnet_client folder and add the following:


   /* Check if the caller requested a modal dialog, and use the appropriate method to
      open the window.  Note that modal dialogs currently only work in Internet Explorer 5.0+ */
   if (summary.modal == "True")
    window.showModalDialog(s,"","dialogWidth:" + width + "px;dialogHeight:" + height + "px;status:no;");
   else
       if (typeof(summary.windowname) == "string")
        ShowNewWindow(s, summary.windowname);

In the code above we saying that if the Modal property is set to true, then show a ModalDialog window, else if the windowname property contains the name of the RadWindow, then show a RadWindow instead.
You also need to add the following JavaScript function inside the WebValidationUI.js:


/* Show new window */
function ShowNewWindow(url, windowname)
{
 //Show new window
    var oWindow = window.radopen (url, windowname);
}


The above code will be responsile for initializing the RadWindow.
The output of the above is shown below:


 
Isn’t this cool [:)]
The above explained is everything you need to use RadWindow with ASP.NET 1.1.

What about ASP.NET 2.0? In ASP.NET 2.0 as you all know the WebValidationUI.js is now embedded in a resource assembly, so there is no way to change the file! What can we do? Thanks to Scott Guthrie who forwarded me to Matt Gibs, who gave me this trick:


Place the aspnet_client folder inside the root of your application and ASP.NET 2.0 will first check if the WebValidationUI.js is found in the same application then it uses it else it will use the one in the resource assembly which is great because the developer is still given the opportunity to change that file!
So to make your code work on ASP.NET 2.0, you simply place the aspnet_client inside the root of your application and that’s it!!


You can download a running ASP.Net 2.0 Web application here.


Hope you enjoyed this article, if you have any questions or comments please don’t hesistate to email me directly!!

Thank you,
Regards

Tags:

May 6 2007

Microsoft ASP.NET 2.0 Ajax - Client Library Webcasts

Category: AJAX-ATLAS | MSDN WebCastsBil@l @ 11:08

Rob Bagby, a Microsoft Developer Evangelist, is running in the coming weeks a series of Webcasts on the Client Side of ASP.NET AJAX, here is the list:

May 5 2007

Visual Studio 2005 - Vista - Tabbed Documents

Category:Bil@l @ 09:13

I have recently installed VS 2005 on a Vista  machine. When I open my VS, I don't see the TABs of all the opened documents. What I see is always a flat view of all the docments.

What went wrong? Well seems when I installed the VS 2005 on Vista, the Tabbed Documents option has been disabled and the Multiple Documents option was selected instead. How to resolve this?

Go to Tool --> Options --> Environment --> General --> On the right window, select Tabbed Documents. That's it!!

Hope this helps.
Regards

Tags:

May 4 2007

MSDN WebCast : ASP.NET AJAX Client Libraries: Calling Web Services

Category: AJAX-ATLAS | MSDN WebCastsBil@l @ 16:46

I have attended the first live MSDN Webcast in my life yesterday by a great presenter Rob Bagby.

Few days ago I watched his first webcast which was ASP.NET AJAX Client Libraries: Overview, he promised to have a series of like 8+ web casts on the same topic!!

Yesterday's webcast was perfect, Rob went into so many details that are very important to know and explained in details how to call Webservices from the client side of AJAX. I advise you to check it out: ASP.NET AJAX Client Libraries: Calling Web Services

I am now attending the Best Practices for Building Next-Generation Web Applications with ASP.NET AJAX.

 

Regards

Tags: ,

May 4 2007

More on AJAX Client Side Life Cycle

Category: AJAX-ATLASBil@l @ 10:59

I must have forgot to mention there is still the Load method after PageLoaded and before EndRequest events!!

Have a graphical look at the client side page life cycle here at this nice blog post by David Barkol: ASP.NET AJAX: Client-side event viewer

 

Hope this helps,

Regards

Tags:

May 2 2007

Microsoft ASP.NET AJAX - Request Life Cycle

Category: AJAX-ATLAS | Telerik ControlsBil@l @ 21:32

I have recently started reading about ASP.NET AJAX. I have been always writing the AJAX code manually using the XMLHttpRequest object and other third-party great controls like the Telerik control!

I decided to work with the FREE Microsoft ASP.NET AJAX.

I would like to share with you a very important issue which is the request-life-cycle. The PageRequestManager that is created on the client side once partial page update is enabled, fires several events in the following order that you can attach your own custom events to:

  1. It first creates a request to the server using the WebRequest client side object
  2. InitializeRequest event fires
  3. BeginRequest event fires
  4. A callback method will be executed once the response is back from the server
  5. PageLoading event fires
  6. UpdatePanels on the page are now updated with the new content
  7. PageLoaded event fires
  8. Load
  9. EndRequest event fires

The items in bold represent the events that will fire during the life of a request from the time it gets created to the time it gets destroyed!

Hope this helps,
Regards

 

Tags: ,

May 1 2007

Microsoft ASP.NET Futures Documentation is there!

Category:Bil@l @ 20:18

Check out the documentation on Microsoft ASP.NET Futures released lately for AJAX, SilverLight, Dynamic Data Controls, and much more!!

http://quickstarts.asp.net/futures/

 

Regards

 

Tags:

Apr 19 2007

Telerik C#/VB.NET Converter

Category: Telerik ControlsBil@l @ 06:18

I would like to inform you about the Telerik Code Converter from C# --> VB.NET and VB.NET --> C#.

The converted code looks great, nicely formatted, saving the original format and spacing!!

Great work Telerik! Thanks!!!

You can check the converter at: http://converter.telerik.com/

HTH,
Regards

Tags:

Apr 4 2007

RegisterHiddenField and ID property

Category: ASP.NET 2.0 - GeneralBil@l @ 10:43

In a previous post I talked about the xListBox and MoverList Controls. I did some fixes to make them work for FireFox and IE.

What was the problem actually? If you read the article about xListBox, you will notice that I have based on solution on a HiddenField to keep track of added/removed items from the ListBox on the client side and to reflect the changes on the server side.

The problem was that, RegisterHiddenField in ASP.NET 1.1, was not generating an ID for the hidden field on the HTML and I was using the document.getElementById, FireFox was having a problem in this, while IE as usual has no problem with anything [:D].

I could have used document.getElementByName, but I prefered to use the one by ID. So what I did is that, I had to customize the way the RegisterHiddenField works. The idea I got from this post: ASP.NET's RegisterHiddenField and document.getElementById

However, I had to modify it a bit to look something as:

    string hiddenFieldName = this.ClientID + "_REMOVED";
    if (!HttpContext.Current.Request.Browser.ToString().Equals("IE"))
        hiddenFieldName =  hiddenFieldName + "\"" + " id=\"" + hiddenFieldName;

This way, I did a trick to add the name of the HiddenField and an ID for the HiddenField and that worked perfect!!

Maybe you can use this trick in your work somewhere!

Hope this helps,
Regards

Tags: