Solved

ASP.NET ImageButton Custom Control

Posted on 2010-09-24
9
431 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

770 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