RenderContents not rendering programmatically set attributes inherited from System.Web.UI.WebControl

Discussion in 'ASP .Net' started by Nathan Sokalski, Jul 30, 2009.

  1. I have a custom control that inherits from System.Web.UI.WebControls.Image.
    When overriding the RenderContents method, I include the following lines of
    code:

    Me.ImageUrl="myurlstring"
    MyBase.RenderContents(writer)

    However, when I run the control, it renders the following:

    <img src="" style="border-width:0px;" />

    Notice that the "src" attribute has an empty string as it's value. However,
    when I ran the debugger, it showed that the specified value did get assigned
    to Me.ImageUrl, so I would expect it to render:

    <img src="myurlstring" style="border-width:0px;" />

    I have tried this same test with other properties such as AlternateText, and
    the same thing happened (they did not render). However, I once wrote a
    custom control that inherited System.Web.UI.WebControls.DropDownList in
    which I override RenderContents the same way (I set an inherited property
    using Me.Property=Value and then call MyBase.RenderContents(writer)), and
    that worked fine. Why is it not working here? Any help would be appreciated.
    Thanks.
    --
    Nathan Sokalski

    http://www.nathansokalski.com/
     
    Nathan Sokalski, Jul 30, 2009
    #1
    1. Advertising

  2. I found my problem. I probably should have realized this sooner (since it's
    something I already knew), but it was simply the fact that the attributes in
    the actual tag are rendered in the Render method, and RenderContents is only
    for children and stuff between the opening and closing tags. Problem Solved!
    --
    Nathan Sokalski

    http://www.nathansokalski.com/

    "Nathan Sokalski" <> wrote in message
    news:...
    >I have a custom control that inherits from System.Web.UI.WebControls.Image.
    >When overriding the RenderContents method, I include the following lines of
    >code:
    >
    > Me.ImageUrl="myurlstring"
    > MyBase.RenderContents(writer)
    >
    > However, when I run the control, it renders the following:
    >
    > <img src="" style="border-width:0px;" />
    >
    > Notice that the "src" attribute has an empty string as it's value.
    > However, when I ran the debugger, it showed that the specified value did
    > get assigned to Me.ImageUrl, so I would expect it to render:
    >
    > <img src="myurlstring" style="border-width:0px;" />
    >
    > I have tried this same test with other properties such as AlternateText,
    > and the same thing happened (they did not render). However, I once wrote a
    > custom control that inherited System.Web.UI.WebControls.DropDownList in
    > which I override RenderContents the same way (I set an inherited property
    > using Me.Property=Value and then call MyBase.RenderContents(writer)), and
    > that worked fine. Why is it not working here? Any help would be
    > appreciated. Thanks.
    > --
    > Nathan Sokalski
    >
    > http://www.nathansokalski.com/
    >
     
    Nathan Sokalski, Jul 31, 2009
    #2
    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. P4trykx
    Replies:
    2
    Views:
    1,835
    bruce barker
    Jan 31, 2007
  2. Nathan Sokalski
    Replies:
    1
    Views:
    541
    Nathan Sokalski
    Jul 31, 2009
  3. Dave

    CssClass property not recognized by Inherited WebControl?

    Dave, Jun 21, 2004, in forum: ASP .Net Building Controls
    Replies:
    3
    Views:
    144
    Victor Garcia Aprea [MVP]
    Jun 22, 2004
  4. Nathan Sokalski

    Inheriting System.Web.UI.WebControls.Image and RenderContents

    Nathan Sokalski, Jul 29, 2009, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    790
    Nathan Sokalski
    Jul 31, 2009
  5. Nathan Sokalski
    Replies:
    1
    Views:
    1,022
    Nathan Sokalski
    Jul 31, 2009
Loading...

Share This Page