Inherit from ImageButton, add text property

Discussion in 'ASP .Net Web Controls' started by MarkMurphy, Jul 6, 2004.

  1. MarkMurphy

    MarkMurphy Guest

    I started searching google, thinking there must be some sample code
    about for adding a text property to an ImageButton so that one could
    easily localize the button. After thinking about it though, I'm
    guessing that one must dynamically generate the image with the text
    embedded. Using other various methods might not yield a button-like
    behavior when rendered.

    Has anyone created a user control that acts like an image button with
    a text property?

    Thanks,

    Mark
    MarkMurphy, Jul 6, 2004
    #1
    1. Advertising

  2. Hi Mark,

    AS for the adding a Text Property for the ImageButton. I think you can
    consider the following means:
    1. Define a own custom ImageButton control which derived from the
    ImageButton but it has a TExt property itself and will set the ParentClass
    (ImageButton)'s ImageUrl depend on this "Text" property.

    2. Build a simple ASP.NET Render control and output the ImageButton's html
    source directly. The ImageButton control infact will be output as the
    following html source:

    <input type="image" name="ImageButton1" id="ImageButton1"
    src="http://msdn.micros
    oft.com/library/toolbar/3.0/images/banners/msdn_masthead_ltr.gif"
    border="0" />

    You can directly render out the above things in the control's render method
    and if you want to add a property to contorl the ImageUrl, it's also simple
    to change the "src" attribute as you like. Do you think so?

    Above are some of my suggestions. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Steven Cheng[MSFT], Jul 6, 2004
    #2
    1. Advertising

  3. MarkMurphy

    MarkMurphy Guest

    Hi Steven,

    Thanks. I was wanting the text property to contain text to be written
    on top of the image. Font properties would be needed as well of
    course. I guess the first question is how would look in HTML. Once
    that is determined, the server control just needs to do the rendering.

    Alternately, I wonder if it might be easier to generate custom GIFs
    with the text dynamically added at request time. I guess and
    HTTPModule would be the method here.

    -Mark
    MarkMurphy, Jul 7, 2004
    #3
  4. Hi Mark,

    Thanks for your followup. From the further description in your last reply,
    it seems that what you want is a new dynamically generated Image which also
    contains a certain Text you set in the control's property, yes?

    If so, I think the first thing is making a ImageGenerator which can
    generate a new Image resource dynamically at runtime. Generally, we can
    use HttpHandler to provide such a Image Generator which use the GDI+ apis,
    here are some tech articles maybe helpful to you:


    #Serving Dynamic Content with HTTP Handlers
    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html
    /httphandl.asp

    #HTTP Handlers for Images in ASP.NET
    http://www.c-sharpcorner.com/Code/2003/June/HTTPHandlersForImages.asp

    #An ASP.NET thumbnail solution
    http://www.codeproject.com/aspnet/thumbtools.asp


    Then, you register this Image Handler in your web application and in your
    custom ImageButton control, set the ImageUrl as the dynamic generate
    Image's url( the url that request the Image handler which return an Image
    stream).


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Steven Cheng[MSFT], Jul 8, 2004
    #4
  5. Hi Mark,

    Have you had a chance to check out the suggestions in my last reply or have
    you got any further ideas on this issue? If there're anything else we can
    help, please feel free to post here. Thanks.

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    http://msdn.microsoft.com/asp.net/whidbey/default.aspx
    Steven Cheng[MSFT], Jul 13, 2004
    #5
  6. MarkMurphy

    MarkMurphy Guest

    I agree with those suggestions. Thanks for checking! Good support!
    MarkMurphy, Jul 14, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrés Giraldo
    Replies:
    2
    Views:
    393
    Andrés Giraldo
    Dec 15, 2003
  2. Henke
    Replies:
    1
    Views:
    631
    Henke
    May 5, 2004
  3. Andy G
    Replies:
    4
    Views:
    3,299
  4. chris
    Replies:
    2
    Views:
    313
    Nicodemus
    Mar 1, 2004
  5. Andrew Backer
    Replies:
    0
    Views:
    202
    Andrew Backer
    Mar 15, 2005
Loading...

Share This Page