Solved

ASP.NET ImageButton Custom Control

Posted on 2010-09-24
9
432 Views
Last Modified: 2013-11-26
Hi I need to create a ASP.NET custom control which is inherited from ImageButton. I need to assign Text Property to it so I can diplay the text on top of the image.

Hope you can help.
0
Comment
Question by:shartan
9 Comments
 
LVL 4

Expert Comment

by:antonybrahin
ID: 33752036
0
 
LVL 1

Expert Comment

by:boogiefromzk
ID: 33752042
Add a property with string type (in fact, I think there already is a caption property) and display it's value in html part as for label control.
0
 

Author Comment

by:shartan
ID: 33752076
Hi Boogiefromzk,

Thanks for the reply. Can you provide me with a sample of what u r suggesting. I am quite new to custom controls.

Thanks
0
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 1

Expert Comment

by:boogiefromzk
ID: 33752267
Sorry, I've went from MS 2 years ago.
See this page for instructons
http://dotnetslackers.com/articles/aspnet/ASPNETCustomControlsPart1.aspx
0
 
LVL 15

Accepted Solution

by:
jorge_toriz earned 500 total points
ID: 33760989
You could use something like this:

public class MyImageButton : ImageButton
{
    protected override void Render(HtmlTextWriter writer)
    {
        writer.Write("<table>");
        writer.Write("<tr><td align=\"center\">");
        writer.Write(Context.Server.HtmlEncode(this.Text));
        writer.Write("</td></tr>");
        writer.Write("<tr><td align=\"center\">");
        base.Render(writer);
        writer.Write("</td></tr>");
        writer.Write("</table>");
    }
}
0
 
LVL 15

Expert Comment

by:jorge_toriz
ID: 33931690
I put a code sample that solves the problem
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question