Mover List Control for ASP.NET 1.x/2.0
page 9 of 14
by Bilal Haidar
Feedback
Average Rating: This article has not yet been rated.
Views (Total / Last 10 Days): 60409/ 152

Public Data Properties

This section in the mover control has been added upon the advice of my colleague Miguel Castro who is an MVP and a well known consultant in the field of .NET. He said that since this is a composite control, which means we are encapsulating controls within this control, it is not wise to simple expose the whole child controls to page developers! And he is absolutely true! What we can do is add some required properties and allow the page developers to configure to make the listboxes and buttons function properly. For instance, we have added style properties to let the page developer, if interested, to add some formatting properties. In addition, we want to allow the page developer to bind some data to the two listboxes. Therefore, it is wise to provide four main properties:

ListBoxDataSource

ListBoxItems

ListBoxDataTextField

ListBoxDataValueField

Those properties have been added for both listobxes. So, we will explain them in a generic way to show you why they have been added.

The ListboxDataSource will be used by page developers to bind any of the two listboxes to any custom collection, array list, dataset, etc … therefore, it is a “set” property only. One of those properties is shown below.

Listing 8

public object LeftListDataSource
{
  set
  {
    this.leftListDataSource = value;
  }
}

The ListBoxItems is a simple “get” property that returns the items present at any moment that control is being accessed. The code is show below:

Listing 9

public ListItemCollection LeftItems
{
  get
  {
    this.EnsureChildControls();
    return this.leftListBox.Items;
  }
}           

First of all, we make sure the controls on the composite control are created and this is done by calling the EnsureChildControls method. This internally checks whether the ChildControlsCreated property is false or true and accordingly calls the CreateChildControls method that we will discuss soon in this article and will mainly build the control tree of this control being developed.

The ListBoxDataTextField, as its name suggests, is used to specify the field that will be shown to the users when the items are added to any of the listboxes. It mainly corresponds to the DataTextField of the controls found in .NET Framework used to display a list of data.

Listing 10

public string LeftListDataTextField
{
  get
  {
    if ((object)ViewState["LeftListDataTextField"] == null)
      return "";
    return (string)ViewState["LeftListDataTextField"];
  }
  set
  {
    ViewState["LeftListDataTextField"] = value;
    this.ChildControlsCreated = false;
  }
}

As mentioned above, the idea behind those properties came to me from Miguel’s article on code-Magazine, Custom Web Controls Demystified, Part 2, and we would strongly recommend checking it out for the richness of information it gives developers in order to develop rich and well constructed controls.

Hint: Never expose the child controls contained in a composite control as public properties. Always do a selection on some properties required for those inner controls and expose them as public properties.


View Entire Article

User Comments

Title: waov   
Name: almora
Date: 2011-04-26 4:09:13 AM
Comment:
Nice info here Bilal, thanks dude.
Title: How to get right side selected value   
Name: Kusum
Date: 2008-05-27 8:12:08 AM
Comment:
Hii,
Can anybody help me that how can I access the right side selected values at server side? I want to save right side selected value in database, so on click of save button, how can I access the right hand side list box item at server? Any property?
- Kusum
Title: Error on Mover control while implementing   
Name: Sandeep
Date: 2008-03-23 11:17:58 AM
Comment:
Hello,
I am getting below error while implementing mover control:

"Control 'leftlstbox' of type 'xListBox' must be placed inside a form tag with runat=server."

Please help me, even through below forum I have tried Peruri Srinivasulu steps.

Thanks,
Sandeep
Title: Re: Vessel   
Name: Bilal Haidar
Date: 2007-11-15 1:25:39 AM
Comment:
Vessel,
I guess, I have used the "," for joining elements. You can change it to something like "|" or "$" or any other not commonly used character.

Thanks
Title: Re: Vessel   
Name: Bilal Haidar
Date: 2007-11-15 1:22:27 AM
Comment:
Hello Vessel,
Are you at the ACK team?

Regards
Title: Ajax version?   
Name: Vessel
Date: 2007-11-14 4:23:30 PM
Comment:
Hi Bilal Haidar

How about to make similar Ajax-control and contribute it with Ajax Control Toolkit.

I think there will be use for it ;)

-Vessel
Title: Index was outside the bounds of the array.   
Name: Vessel
Date: 2007-11-14 3:59:26 PM
Comment:
If list item have comma ',' inside, control will crash, maybe your problem too purusingh.

Crash-item: "Choose me, Buddy"
Okay-item: "Choose me Buddy"

So, while populating list-items sanitize commas out.
Title: Re: purusingh   
Name: Bilal Haidar
Date: 2007-10-15 11:32:24 AM
Comment:
Hello,
Can you please show me some code where this exception is generated?
I have been using this control for a while and haven't got such an exception!

Just to note, such an error occurs when you are trying to access elements inside the control that are not present i.e. accessing with index greater than the max. index inside the control!

Thanks
Title: Good Article   
Name: purusingh
Date: 2007-10-15 5:33:41 AM
Comment:
Every thins is ok, we are using the control but there is some problem I am getting following error


Index was outside the bounds of the array.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:


[IndexOutOfRangeException: Index was outside the bounds of the array.]
xListControls.xListBox.System.Web.UI.IPostBackDataHandler.LoadPostData(String postDataKey, NameValueCollection postCollection) +1486
System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +723
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4798
Title: good articles   
Name: good articles
Date: 2007-09-24 3:54:34 AM
Comment:
very good!!!
Title: Re: Vessel   
Name: Bilal Hadiar [MVP]
Date: 2007-04-04 1:53:56 AM
Comment:
Hello Vessel,
Can you illustrate more please?

Thanks
Title: Index was outside the bounds of the array.   
Name: Vessel
Date: 2007-03-24 2:38:07 PM
Comment:
MoverControl can't stand with ',' in ListItemValue because it uses comma as inside delimiter.

Array-handling crashes with 'Index was outside the bounds of the array.'

Took awhile to find it out ;)
Title: This is not working for me   
Name: Daniel
Date: 2007-03-21 10:10:14 AM
Comment:
IM loading the left list to a db object but when I click on the arrow to move it I notice that the page load happens several times and doesnt move teh object.
Title: error when programatically creating control   
Name: Peruri Srinivasulu
Date: 2007-02-14 10:24:59 PM
Comment:
{"Control 'ctl02_leftlstbox' of type 'xListBox' must be placed inside a form tag with runat=server."}

when placed the following code in page init.


protected override void OnInit(EventArgs e)
{
base.OnInit(e);

MoverControl.bhMover moveR1 = new bhMover();
this.Controls.Add(moveR1);
}
Title: Good Work   
Name: Tim Digital
Date: 2007-02-09 8:42:19 AM
Comment:
Excellent Work Bilal,

Fluent consulting also has a pretty neat control (ListTransfer)that I've been using in my projects :-

http://www.fluentconsulting.com/components/Fluent.ListTransfer/
Title: Good article   
Name: vishal rathod
Date: 2007-01-29 9:01:02 AM
Comment:
Nice article.
and exactly what i want.
Title: Nice Work as Usual   
Name: El Chokr
Date: 2007-01-09 3:05:45 PM
Comment:
Nice Work as Usual
Title: nice   
Name: pranot
Date: 2007-01-08 4:31:10 AM
Comment:
really nice and exactly what i was looking for
i just spent 2 days writing something similar but using client-side javascript to move items.
also, it would be helpful if you could provide some screenshots, and a working demo which can be viewed online.
Title: Good Article   
Name: Haissam Abdul Malak
Date: 2007-01-08 2:51:47 AM
Comment:
Good article, keep up the good work

Best Regards

Product Spotlight
Product Spotlight 





Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2021 ASPAlliance.com  |  Page Processed at 2021-12-08 11:59:50 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search