Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Professional
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 29th, 2006, 12:36 AM
Registered User
 
Join Date: Aug 2006
Location: Ahmedabad, Gujarat, India.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Custom DropDownList Control with selectable images

Hi, I am developing a custom DropDownList control in ASP .NET 2.0 (C#).

It is derived from System.Web.UI.WebControls.DropDownList class.

DropDownList is to be extended to allow the control user to select the image for the drop down button. Actually, two images - one default image and the one image for mouse over can be selected by the user.

For this purpose, I have added two properties "ImageUrl" and "MouseOverImageUrl".

My problems are:

1. How can I make these properties behave like "ImageUrl" property of ImageButton where Image Path selection dialog appears? Currently, I have to type the urls manually.

2. DropDownList control renders html's "select" tag and I am not aware which attributes should I set so that the control is rendered with the drop down button images given by the user.

Please Help as early as possible.

Thanks in advance,

Hitul

Hitul J. Patel
Software Engineer
  #2 (permalink)  
Old August 29th, 2006, 02:08 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,048
Thanks: 80
Thanked 1,581 Times in 1,558 Posts
Default

Hi Hitul,

If I understand you correctly: you can't. The arrow on the drop down button is defined by the operating system and cannot be changed by HTML, script or CSS.

You could create a full JavaScript solution and recreate the drop-down control with client side JavaScript. Not an easy thing to do though...

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #3 (permalink)  
Old August 29th, 2006, 06:05 AM
Registered User
 
Join Date: Aug 2006
Location: Ahmedabad, Gujarat, India.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Hi Imar,

Yes, you understood it correctly. I am not so good at javascripts, rather I shall try developing a custom control combining a lable, an image and a listbox.

By the way, thank you very much,

Hitul

Hitul J. Patel
Software Engineer
  #4 (permalink)  
Old August 29th, 2006, 06:20 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,048
Thanks: 80
Thanked 1,581 Times in 1,558 Posts
Default

Good luck....

Imar
  #5 (permalink)  
Old October 3rd, 2006, 08:07 AM
Authorized User
 
Join Date: Apr 2005
Location: , , .
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

See AspLib HtmlDropDown control (http://asplib.net). You can create liked

  #6 (permalink)  
Old November 28th, 2006, 06:39 AM
Registered User
 
Join Date: Aug 2006
Location: Ahmedabad, Gujarat, India.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Well, I have sorted out the said problem using ImageUrlEditor. Now, I'm facing some trivial problem. It goes like this. e.g. When we place an Image control on webpage, and when we assign ImageUrl to the control, the image is automatically is displayed in DESIGN VIEW of Visual Studio, and no image icon gets disappeared. The same does not happen with my custom drop down list control. The ImageUrl is set at Design time, the image is displayed at run time, but does not display at DESIGN TIME. Following is the relevant code from my custom control class. Please help me, if you know the solution.

        [Category("Appearance")]
        [Localizable(true)]
        [Description("The URL of the image to be shown as Drop Down Button.")]
        [Editor("System.Web.UI.Design.ImageUrlEditor, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", typeof(UITypeEditor))]
        [DefaultValue("")]
        [UrlProperty]
        [Bindable(true)]
        public string ImageUrl
        {
            get
            {
                return ImageBtn.ImageUrl;
            }

            set
            {
                ImageBtn.ImageUrl = value;
            }
        }

This is how ImageUrl property is defined in the control. Here, ImageBtn is an object of Image class.

Please Help.

Hitul J. Patel
Software Engineer
  #7 (permalink)  
Old November 28th, 2006, 06:15 PM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,048
Thanks: 80
Thanked 1,581 Times in 1,558 Posts
Default

The problem is that the code isn't run until run-time, so the Design Surface doesn't know you're setting an image URL.

One solution is with Design Time images, although AFAIK this only works with *server controls*, not with User Controls:

http://www.nikhilk.net/WebResourceAt...esignTime.aspx

Alternatively, instead of exposing the ImageUrl you could expose the Image. I think the Design View then knows the property has been set and updates the design surface. Not a pretty solution, so it's worth looking into the post I linked to.

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #8 (permalink)  
Old November 29th, 2006, 03:26 AM
Registered User
 
Join Date: Aug 2006
Location: Ahmedabad, Gujarat, India.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Hi Imar,

First of all, Thank you very much.

Well, I didn't get you when you say "The problem is that the code isn't run until run-time, so the Design Surface doesn't know you're setting an image URL."

The Render method of the control renders Image control and Image control's ImageUrl property is set well before which can be seen while debugging. Still it does not display the image I set, though it displays ImageUrl I set in properties dialog.

Code:
protected override void Render(HtmlTextWriter output)
{
       ........... Some Code ..........
       if(DesignMode)
       {
            ImageBtn.RenderControl(output);
       }
       ........... Some Code ..........
}
I have no other option than to use ImageUrl property. And being custom control, I have to allow the end user (web site developer) to set the image as he would like to see as a drop down button, so embedding images as a resource is also not a solution for my problem.

When I derive my control from Image, it displays image at design time while setting ImageUrl. But my control is derived from DataBoundControl and which I can't change. So, I think there must be some tweak which I don't know.

Thanks,


Hitul J. Patel
Software Engineer
  #9 (permalink)  
Old November 29th, 2006, 10:39 AM
Imar's Avatar
Wrox Author
Points: 71,804, Level: 100
Points: 71,804, Level: 100 Points: 71,804, Level: 100 Points: 71,804, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,048
Thanks: 80
Thanked 1,581 Times in 1,558 Posts
Default

I think you misunderstood me, or I misunderstood you.

You're talking about the image at Design Time right? Then it won't work if you simply set a property ImageUrl and render it at *run-time*. This works fine when the control is displayed on a page, but not in Visual Studio.

Using the resource syntax *is* the solution to the problem. That's exactly how normal server controls do it too. The resource syntax allows you to display the image both at design time and at run-time.

Quote:
quote:ImageUrl property is set well before which can be seen while debugging
When you debug the final page, or when you debug a separate instance of Visual Studio to debug the actual design time of the control?

You need to look into Control Designers. If you Google for "Control Designers .NET" you'll find some interesting stuff.

If this isn't what you're after, I don't understand the problem. In that case, can you elaborate a little more?

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
  #10 (permalink)  
Old November 30th, 2006, 01:55 AM
Registered User
 
Join Date: Aug 2006
Location: Ahmedabad, Gujarat, India.
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default


Hi Imar,

I think, I need to give you some more details. Well, my control has ImageUrl property so that the user (the developer who will use my control in his web app) can use his/her custom image for Drop Down Button. So, I think using image as a web resource may not help, since we do not want to embed image with the control itself, and we want to develop control whose behavior matches behavior of standard controls. If you still think that I should use image as a resource, please tell me.

Please try to understand following example to better understand my problem.
"When we place a standard Image control on webpage, and when we set ImageUrl property using properties' dialog, the image is automatically displayed in DESIGN VIEW of Visual Studio, and standard "No Image" icon disappeares."

The same does not happen with my custom drop down list control. i.e. When I set ImageUrl property of my control, the control does not display the custom image in DESIGN VIEW of Visual Studio and still it displays standard "No Image" icon.

Secondly, I would like to extend the code snippet of Render method I wrote in my last reply for your clarity.
Code:
protected override void Render(HtmlTextWriter output)
{
       ........... Some Code ..........
       if(DesignMode)
       {
            .......Render other items........
            ImageBtn.RenderControl(output);
            .......Render other items........
       }
       else//Run Time
       {
            .......Render other items........
            ImageBtn.RenderControl(output);
            .......Render other items........
       }
       ........... Some Code ..........
}
Above code shows that I do render control at Design Time also. It proves that the control is rendered at Design Time also, since if I remove ImageBtn.RenderControl(output); in Render method from DesignMode code block, it will not render the image control itself.

I think rendering control outputs HTML which can be understood by Visual Studio IDE Designer. I think it could be better if I could show you the screen shot.

About debugging at Design Time, yes you are right, I use separate instance of Visual Studio.

Finally, I've searched everywhere Google, MSDN, .NET forums etc. but no solution yet. :(

Thanks a lot for your help.

If you are still not clear of something, please ask.

Regards,
Hitul Patel


Hitul J. Patel
Software Engineer
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Custom Server Control....Custom Property Editor ZArrinPour ASP.NET 1.0 and 1.1 Basics 1 June 15th, 2010 12:30 PM
Web Service, Custom Control, Custom Return Type robzyc ASP.NET 2.0 Basics 6 June 10th, 2008 09:03 AM
custom control inside custom control issues StevesonD ASP.NET 2.0 Professional 1 February 19th, 2008 06:54 PM
Help! Custom Server Control using User Control diehard ASP.NET 1.0 and 1.1 Professional 2 January 4th, 2006 12:33 PM



All times are GMT -4. The time now is 06:31 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.