Click here to Skip to main content
15,888,337 members
Articles / Web Development / ASP.NET
Article

Image Gallery 1.0

Rate me:
Please Sign up or sign in to vote.
3.47/5 (36 votes)
29 Feb 2008CPOL3 min read 97.1K   1.7K   69   33
An article on how to create an advanced web custom control for image display.

Image 1

Introduction

Image gallery 1.0 is a custom control with full design time support. This article will give you complete information on creating custom controls, complex properties, inner properties and smart tags, and how to provide design time support in custom controls. This control gives you the solution for showing images like BBC and CNN news websites do. It also provide the auto next (slide show) feature, and some image changing styles.

How to use

To use the Image Gallery 1.0 control on your website, you will need to add the control into the toolbox by right-clicking it, selecting 'Customize Toolbox', selecting the '.NET Framework Components' tab, and then clicking on the Browse button. Navigate to the ImageGallery.dll. This should add it to the toolbox. Then, just drag this control onto the page where you want the control to be.

Image Gallery 1.0 shows you how to add complex properties like GridViews.

ASP.NET
<cc1:Gallery ID="Gallery1" runat="server">

    <NavigationItemBarItemStyle BackColor="#5F74A3" Height="20px" Width="20px" />
    <TitleStyle Font-Bold="True" Font-Size="16px" ForeColor="Black" />
    <NavigationItemBarSelectedItemStyle BackColor="#8C9FCA" Height="20px" Width="20px" />
    <NavigationBarStyle HorizontalAlign="Center" />
    <ImageStyle Height="300px" Width="400px" />
    <DescriptionStyle Font-Size="10px" Height="75px" />
    <NavigationItemBarHoverItemStyle BackColor="#8C9FCA" Height="20px" Width="20px" />
    
    <Images>
        <cc1:Image ImageUrl="~/images/p1.jpg" Selected="true" />
        <cc1:Image ImageUrl="~/images/p2.jpg" Selected="false" />
        <cc1:Image ImageUrl="~/images/p3.jpg" Selected="false" />                   
    </Images>
    
</cc1:Gallery>

Details of some properties:

  • AutoNext: is used for automatically showing the next image after a specific time set in the AutoNextAfter property.
  • AutoNextAfter: is the auto-next time, in seconds.
  • DataSource: is used for binding images from a specific data source.
  • DataImageField: is the field in the data source which provides the image URL.
  • DataTitleField: is the field in the data source which provides the image title.
  • DataDescriptionField: is the field in the data source which provides the image description.
  • ShowTitle: is used for the setting the image title visibility.
  • ShowDescription: is used for the setting the image description visibility.
  • ShowNavigationBar: is used for the setting the navigation bar visibility.
  • ImageFolder: is used for setting the path of the image folder from which the user wants to display an image.
  • ImagesExtensions: contains the comma separated list of image extensions.
  • ImageChangeStyle: is used to set the image changing style.

How to add images

User can select or add images in three ways:

  1. Add images to an image collection. The Images property is used for adding images to the control.
  2. Select the path of the folder in which images exist, using the ImageFolder property.
  3. Using a data source

Image 2

The Images property is used to store the collection of images. The Images property is a collection base; during design time, it will be an open collection editor.

Image 3

The Images property is an inner property; so, we add a property level metadata attribute [PersistenceMode(PersistenceMode.InnerProperty)].

C#
[DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
[PersistenceMode(PersistenceMode.InnerProperty)]
[Description("Images")]
public ImageCollection Images
{
    get
    {
        if (_images == null)
            _images = new ImageCollection();
        return _images;
    }
}

The ImageCollection class is inherited from the CollectionBase class and the CollectionBase class is used to create a custom collection.

C#
public class ImageCollection : CollectionBase
{
    public Image this[int index]
    {
        get{ return (Image)this.List[index];}
        set{this.List[index] = value;}
    }
    
    public void Add(Image image)
    {
        image.Index = this.List.Count;
        this.List.Add(image);
    }
    
    public void Insert(int index, Image image)
    {
        this.List.Insert(index, image);
    }
    
    public void Remove(Image image)
    {
        this.List.Remove(image);
    }
    
    public bool Contains(Image image)
    {
        return this.List.Contains(image);
    }

    public int IndexOf(Image image)
    {
        return this.List.IndexOf(image);
    }

    public void CopyTo(Array array, int index)
    {
        this.List.CopyTo(array, index);
    }
}

Smart Tag

This control provides full design-time support. You can also set the properties using a Smart Tag. The user can also apply some pre-defined styles using auto-format. This article explains how to create professional a Smart Tag.

Image 4

For creating a Smart Tag, create a designer class and inherit it from System.Web.UI.Design.ControlDesigner. The designer class handles the behavior of a control on the design surface. We can override methods of the ControlDesigner class for design-time support. In this article, I will explain only one method, which is used to handle a Smart Tag. For displaying a Smart Tag, we override the ActionLists property of the ControlDesigner class.

C#
class GalleryDesigner : System.Web.UI.Design.ControlDesigner
{ 
    DesignerActionListCollection _actionList = null;
    
    public override DesignerActionListCollection ActionLists
    {
        get
        {
            if (_actionList == null)
            {
                _actionList = new DesignerActionListCollection();
                _actionList.Add( new GalleryActionList(this));
            }                
                           
            return _actionList;
        }
    }
}

ActionLists returns the list of all actions which show on the Smart Tag. In this article, we get this list from GalleryActionList, which is inherited from the System.ComponentModel.Design.DesignerActionList class, and we override its method GetSortedActionItems() as shown below:

C#
class GalleryActionList : System.ComponentModel.Design.DesignerActionList
{
    #region OVERRIDED METHODS

    public override DesignerActionItemCollection GetSortedActionItems()
    {

        DesignerActionItemCollection list = new DesignerActionItemCollection();
        list.Add(new DesignerActionMethodItem(this, "ShowAutoFormat", 
                 "Auto Format...", "Format"));            
        list.Add(new DesignerActionMethodItem(this, "EditImages", 
                 "Images...", "images"));
        list.Add(new DesignerActionPropertyItem("ShowTitle", 
                 "Show Title", "Other"));
        list.Add(new DesignerActionPropertyItem("ShowDescription", 
                 "Show Description", "Other"));

        return list;
    }

    #endregion
}

Points of interest

During the development of this control, I found one major issue which was how to add images from a Smart Tag. I tried to solve it through many ways, but was unable to solve it successfully, because changes from the Smart Tag were not reflecting properly on the page. Finally, I got a solution from a forum. The solution is available in the EditorServiceContext.cs file.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Chief Technology Officer
Pakistan Pakistan
Passion and positive dedication is essential part of success. I believe on hardworking and sharing knowledge with others. I always try to be a better than I am and think positive for positive result.

My Blogs

My Linked-In Profile

Comments and Discussions

 
QuestionAdd function Pin
daniel campuzano5-Feb-13 1:12
daniel campuzano5-Feb-13 1:12 
GeneralMy vote of 4 Pin
z4rk30-Nov-11 22:44
z4rk30-Nov-11 22:44 
GeneralTwo copies of the control on the one page does not increment correctly Pin
garethwilliams7-Oct-10 1:07
garethwilliams7-Oct-10 1:07 
Generalfive ***** from me ;) Pin
hammad3218-Jan-10 6:07
hammad3218-Jan-10 6:07 
GeneralRe: five ***** from me ;) Pin
Shakeel Iqbal18-Jan-10 6:45
Shakeel Iqbal18-Jan-10 6:45 
Generalclick and pass url Pin
jinboh1-Jan-10 5:11
jinboh1-Jan-10 5:11 
GeneralRe : Image Starts from 1 not 0 Pin
Member 7509852-Dec-09 6:28
Member 7509852-Dec-09 6:28 
GeneralRe : Page Navigation bar Top Pin
Member 75098516-Nov-09 4:37
Member 75098516-Nov-09 4:37 
GeneralRe: Re : Page Navigation bar Top Pin
Shakeel Iqbal17-Nov-09 6:14
Shakeel Iqbal17-Nov-09 6:14 
QuestionImage Style For Each Different Image? Pin
isidat25-Aug-09 4:28
isidat25-Aug-09 4:28 
AnswerRe: Image Style For Each Different Image? Pin
Shakeel Iqbal26-Aug-09 20:33
Shakeel Iqbal26-Aug-09 20:33 
GeneralAdd function Pin
daniel campuzano5-Feb-13 1:11
daniel campuzano5-Feb-13 1:11 
QuestionHow can I make the image at the center of the image container? Pin
isidat23-Aug-09 13:32
isidat23-Aug-09 13:32 
AnswerRe: How can I make the image at the center of the image container? Pin
Shakeel Iqbal23-Aug-09 21:36
Shakeel Iqbal23-Aug-09 21:36 
GeneralRe: How can I make the image at the center of the image container? Pin
isidat24-Aug-09 0:10
isidat24-Aug-09 0:10 
QuestionHi, Can you give the Image more effect? Pin
JLKEngine00814-Sep-08 16:48
JLKEngine00814-Sep-08 16:48 
GeneralCITIES/TOWNS IN KASHMIR NAMED MAGRAY Pin
RABIA ANWER MAGRAY31-Aug-08 8:15
RABIA ANWER MAGRAY31-Aug-08 8:15 
GeneralMAGRAY- A MARTIAL& A WARRIOR KASHMIRI TRIBE/CASTE/RACE Pin
RABIA ANWER MAGRAY31-Aug-08 8:07
RABIA ANWER MAGRAY31-Aug-08 8:07 
MAGRAY A MARTIAL &amp; A WARRIOR KASHMIRI TRIBE:
Also known and spelled as MAGRI, MAGRE &amp; MAGREY. But the correct spelling is MAGRAY. Pleural of MAGRAY is MAGRES.anwerrabia076@gmail.com
Magray is a Martial Kashmiri tribe of Rajput origin. Magray sprung from Kashtri-un-Nassal Rajput. Kashtri-un-Nassal Rajput are one of the four classes of Hindus. Kashtri were people of ruling class having responsibility for the defence of the state. Ladhay Magray was the forefather of Magray tribe. Magres accepted Islam at the hand of Syed Ali Hamdani in thirteenth Century. The first person who entered in Kashmir and settled there belonged to Magray tribe thus making Magray tribe, the founders of Kashmir. Magray tribe ruled over Kashmir for seven hundred years. They invited Mughals to enter Kashmir in order to end disturbances in the valley. However, subsequently Mughals were defeated and pushed back by the Magray tribe. Magray tribe is settled all over the world with majority in Kashmir Valley. In spite of being SARDARS of the time, people of Magray tribe felt proud to be called as MAGRAY.
VILLAGES &amp; TOWNS IN KASHMIR NAMED MAGRAY:
1.Magray Village, District Bagh
2. Magray City, Kuttan, Neelum valley, Muzaffarabad
3.Magray Hills, Kanchikot, Rawalakot
4. Magray Abad, Rawalakot
5. Magray Gali, Lipa Valley, Muzaffarabad
6. Magray Abad, Athmaqam,Kel road,Neelum Valley
7. Magray Village,Motarin, khaigala, Rawalakot
8.Kharl Magrayay,District Bagh
9 Sardari Magrayan,Neelum Valley Muzaffarabad
10.Magray Village Marchkot,Abbaspur
11.Bandian Magray,Abbaspur
MEANINGS OF MAGRAY:
Magray is an ancient word, Magray means, "The Martials", "The Warriors", "Military and war like people". Magray is also spelled as Magrey, Magre and Magri, but the correct spelling is Magray. The plural of Magray is Magres.
HISTORRICAL BOOKS ON MAGRAY TRIBE:
All the historical books on Kashmir contain material on Magray tribe and their role in the history of Kashmir. Few of the historical Books are mentioned here for reference.
1. Magray in the Eyes of History By Sajid Latif Magray
2. Magray A Warrior Kashmiri Tribe By Abdul Qayyum
3. Valley of Kashmir By Sir Walter Lirance
4. Imperial Gazettier of India Govt of India
5. Tribes and Castes of Kashmir By Muhammad Din Folk
6 .Castes and Tribes of Poonch By Muhammad Din Folk
7. History of Kasmir By Khawaja Azamey
8. History of Kashmir By Muhammad Hassan
9. History Kabeer Kashmir By Haji M.Mohiudin
10.Raj Tarangi By Pandit Kahlan
11. Tareekh-e-Kashmir By Professors Nazir Ahmed Tashna
12. Kashmir in the Era of Muslim empires By Ghulam Hassan Khoyami
13. Tareekh-e- Malkan By Dr Sadiq Malik
14. Jalwa-e-Kashmir By Dr Sabir Afaqi
15 Baharistan-e-Shahi A Chronocle Mediaeval of Kashmir
16. Magray- The Martials and Warriors of Kashmir By Sajiad Latif Magray
17. Tareekh-e-Kashmir,Islamia By Dr Sabir Afaqi
18. Tareekh-e-Azmi By M.Azam
19. Tribal geography of India Jamu and Kashmir By Muhammad Bashir Magray
20. A New History of India and PakistanBy Quyyam Abdul
MAGRAY VILLAGES IN KASHMIR:
1.MAGRAY VILLAGE MOTARIN, RAWALKOT:This is a village comprising of about 400 houses, exclusively of the Magray Tribe. Road leading from Rawalkot to Tatrinote crossing point passes from this village. Few personalities of the village are:-
a. Muhammad Din Magray
b. Subedar Muhammad Latif Magray
c. Sajjad Latif Magray
d. Rasheed Magray
e. Yaqoob Magray
f. Manzoor Magray
g. Sadique Magray
h. Dilpazir Magray
i. Muhammad Aamir Magray
j. Bashir Magray
k. Qayyum Magray
l. Yaseen Magray
m. Imran Yaseen margay
n. Shafi Magray
o. Akram Magray
p. Rafique Magray
q. Sajjad Magray
r. Muhammad Javed Magray
s. Kabir Magray
t. Kamran Magray
2.MAGRAY HILLS KANCHIKOT:This is a big village which starts from the Magray Market on Ali Sajad Road and goes to the top of Tolipeer, a prominent Hill top of Kashmir. Few personalities of the Magray Hills are:-
a. Haji Aqal Hussain Magray
b. Tariq Magray
c. Ghulam Nabi Magray
d. Gulzar Magray
e. Havildar Yaseen margay
f. Subedar Rafique Magray
g. Hanif Magray
h. Havildar Azam Magray
i. Muhammad Ashraf Magray
j. Kala Khan Magray
k. Hakim din Magray
l. Capt Yaqoob Magray
m. Asghar Magray
n. Sadique Magray
o. Haji Abdullah Magr
3.MAGRAY ABAD RAWALAKOT:This is a small town in Rawalakot valley on Banjora Road in Barmang. Few of the personalities of the area are:-
a. Abdul Majeed Magray
b. Muhammad Arif Magray
c. Muhammad Razaque Magray
d. Muhammad Imtiaz Magray
e. Muhammad javed Magray
f. Muhammad Shoukat Magray
g. Muhammad Riaz Magray
h. Muhammad Ishaque Magray
i. Muhammad Shakeel Magray
j. Muhammad Jahangir Magray
k. Muhammad Khurshid Magray
l. Muhammad yaseen Magray
4.MAGRAY VILLAGE BAGH:
This village start from Magray city Lower Bela and extends tol the prominent Hill top of Kashmir Lasdana. This village comprises of 600 houses 100% of the Magray tribe people. Few personalities of the Magrtay village are:-
a. Dr Mir Akbar Magray
b. Gohar Magray
c. Abdul Hameed Magray
d. Fazal Gohar Magray
e. Aslam Magray
f. Hayat margay
g. Liaqat Ali Magray
h. Ghulam Nabi
i. Wali Noor Magray
j. Sakhi Muhammad Magray
k. Haseeb Magray
5.KHARL MAGRAYAN:
It is a small area in District Bagh, people of Magray tribe are settled here. Few personalities of the area are:-
a. Muhammad Ashraf Magray
b. Muhammad Farooq Magray
c. Abdul Hameed Magray
d. Gulfraz Magray
e. Akram Magray
f. Haji Hakeek Magray
g. Muhammad Khurshid Magray
h. Fazal Hussain Magray
i. Shakeel Ahmed Magray
6.MAGRAY GALI LIPA:
A prominent Hilltop of Kashmir in Lipa valley. Few personalities of the area are lmentioned here:-
a. Capt Ghulam Hussain Magray
b. Ghulam Rasool Magray
c. Pervaiz Magray
d. Prof Kosar Magray
7.MAGRAY CITY KUTTAN:
Few notables of the area are:-
a. Mangta Magray
b. Shahzaman Magray
c. Arshad Magray
d. Shahzaman Magray
e. Ali Akbar Magray
f. Asad Magray
g. Matloob Magray
h. Attique Magray
i. Oamer Zaman Magray
j. Amjid Magray
8.MAGRAY ABAD ATHMAQAM:
A SMALL TOWN IN Neelum valley on Kel Road near Athmaqam. Few personalities of the area are:-
a. Muhammad Mustafa Magray
b. Muhammad Khurshid Magray
c. Muhammad Subhan Magray
d. Shakeel Magray
e. Ashraf Magray
f. Mushtaq Magray
g. Ghulam Hussain Magray
h. Abid Magray
9.SARDARI MAGRAYAN – REMOTE AREA OF NEELUM VALLEY:
10.MAGRAY VILLAGE MARCHKOT:
This is the larges village of Abbaspur town comprising of more than 1000 houses exclusively of the Magray Tibe. Few personalities of the village are:-
a. Sher Akbar Magray
b. Havildar Karim Magray
c. Muhammad Sharif Magray
d. Muhammad Afsar Magray
e. Muhammad Rasheed Magray
f. Manzoor Magray
g. Muhammad Rafique Magray
h. Muhammad Raheem Magray
i. Saleem Magray
j. Ali Akbar Magray
k. Muhammad Azeem Magray
l. Muhammad Yaqoob Magray
m. Mubashar Salam Din Magray
n. Sadique Magray
o. Hameed Magray
p. Kutab Dinb Magray
11.BANDIAN MAGRAY:This is a remote village of Abbaspur town comprising of more than 500 houses entirely of the Magray tribe. Few personalities of Bandian Magray are:-
a. Muhammad Arif Magray
b. Mir Akbar Magray
c. Muhammad Bashir Magray
d. Muhammad Ashraf Magray
e. Muhammad Nazir Magray
f. Sakhi Muhammad Magray
g. Jalal Din Magray
h. Muhammad Saddique Magray
i. Shoukat Magray
j. Rasheed Magray
HISTORY OF MAGRAY TRIBE
TWO BOOKS “MAGRAY THE MARTIALS AND WARRIORS OF KASHMIR”AND “MAGRAY IN THE EYES OF HISTORY”HAVE BEEN WRITTEN BY SAJJAD LATIF MAGRAY .LAUNCHING CEREMONY OF THESE BOOKS WAS HELD ON 1st FEB 08 AT PRESS CLUB RAWALPINDI AND WAS ATTENDED BY THE PRIME MINISTER OF AJ&amp;K AND HIS CABINET MEMBERS.TITLE OF BOOKS ARE WRITTEN BY THE FOL KNOWN SCHALOURS AND HISTORIANS OF THE COUNTRY.
1. DR. M. ASHRAF QURESHI – CHAIRMAN DEPTT OF KASHMIRIYAT PUNJAB UNIVERISTY LAHORE.
2. DR.SABIR AFAQI – AUTHOR &amp; HISTORIAN
3. DR.M.SADIQ MALIK -AUTHOR &amp; HISTORIAN
ORGANIZATIONS OF MAGRAY TRIB:
1 MAGRAY SUPREME COUNCIL: IS THE
SUPREME BODY OF MAGRAY TRIBE,
EMPOWERED TO TAKE ALL SORT OF POLITICAL AND SOCIO ECONOMICAL DECISIONS IN THE BEST INTEREST OF MAGRAY TRIBE.
2. MAGRAY EDUCATIONAL SOCIETY (REGD): PROMOTES EDUCATIONAL ACTIVITIES IN THE TRIBE AND EVEN OUTSIDE THE MAGRAY TRIBE.
3. MAGRAY TANZEEM (REGD): WAS ESTABLISHED TO PROVIDE A PLATFORM AND ORGANIZE THE MAGRAY TRIBE.
4. MAGRAY WELFARE TRUST: LOOKS AFTER THE ILL, POOR AND NEEDY PEOPLE OF THE KASHMIR IN PARTICULAR AND PAKISTAN IN GENERAL.
GeneralHelp is required! Pin
Sobia Saeed Magray9-Jun-08 19:16
Sobia Saeed Magray9-Jun-08 19:16 
Generaldatasource Pin
TaTes7-Jun-08 13:01
TaTes7-Jun-08 13:01 
Generalnice work Pin
TaTes4-Jun-08 2:38
TaTes4-Jun-08 2:38 
GeneralRe: nice work Pin
Shakeel Iqbal4-Jun-08 2:44
Shakeel Iqbal4-Jun-08 2:44 
GeneralNice Article Pin
akadiwala3-Apr-08 7:21
akadiwala3-Apr-08 7:21 
GeneralExcellent work Pin
Afaak24-Mar-08 6:49
Afaak24-Mar-08 6:49 
GeneralNice control but AutoNext doesn´t work Pin
Glauter18-Mar-08 7:21
Glauter18-Mar-08 7:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.