Inheriting style and properties

Discussion in 'ASP .Net Building Controls' started by Jay, Jul 26, 2004.

  1. Jay

    Jay Guest

    I have subclassed RadioButtonList to add the mouseover and mouseout events to individual options. As far as I can see I have to totally rewrite the render method. The way I did it I have not included any inherited styles and properties. How do I inherit the styles and properties that have been set by the developer. I can add styles by using AddStyleAttribute. I can also determine what styles have been set using Me.style.keys and then add them using AddAtyleAttribute. Seems like there should be a way to add all at once all the styles that are inherited. Similarly, I cannot figure out how to add properties like Forecolor all at once.

    I tried to override AddAttributesToRender but i do not seem to ever execute that method.

    Help?

    Jay
     
    Jay, Jul 26, 2004
    #1
    1. Advertising

  2. Are you calling base.Render when you're done with your code?

    --
    John Saunders
    johnwsaundersiii at hotmail

    "Jay" <> wrote in message news:...
    I have subclassed RadioButtonList to add the mouseover and mouseout events to individual options. As far as I can see I have to totally rewrite the render method. The way I did it I have not included any inherited styles and properties. How do I inherit the styles and properties that have been set by the developer. I can add styles by using AddStyleAttribute. I can also determine what styles have been set using Me.style.keys and then add them using AddAtyleAttribute. Seems like there should be a way to add all at once all the styles that are inherited. Similarly, I cannot figure out how to add properties like Forecolor all at once.

    I tried to override AddAttributesToRender but i do not seem to ever execute that method.

    Help?

    Jay
     
    John Saunders, Jul 26, 2004
    #2
    1. Advertising

  3. Jay

    Jay Guest

    No. I do call base.render. Base.render will display the original radiobuttonlist. The only way to add mouseover events to the individual options is to redo the render method entirely.

    Jay
    "John Saunders" <> wrote in message news:...
    Are you calling base.Render when you're done with your code?

    --
    John Saunders
    johnwsaundersiii at hotmail

    "Jay" <> wrote in message news:...
    I have subclassed RadioButtonList to add the mouseover and mouseout events to individual options. As far as I can see I have to totally rewrite the render method. The way I did it I have not included any inherited styles and properties. How do I inherit the styles and properties that have been set by the developer. I can add styles by using AddStyleAttribute. I can also determine what styles have been set using Me.style.keys and then add them using AddAtyleAttribute. Seems like there should be a way to add all at once all the styles that are inherited. Similarly, I cannot figure out how to add properties like Forecolor all at once.

    I tried to override AddAttributesToRender but i do not seem to ever execute that method.

    Help?

    Jay
     
    Jay, Jul 26, 2004
    #3
  4. Jay,

    Your problem is that you _have_ inherited the styles and properties of the base control. You then chose to ignore them in your Render override. The base control Render method knows what to do with the properties of the base control, but you don't call the base control Render method.

    Take a look at the RenderItem method. The following worked in VS Web Developer Express Beta 1:

    #region Using directives

    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    #endregion

    namespace JWS.WebInfrastructure.WebControls
    {
    public class MyRadioButtonList : RadioButtonList
    {
    public MyRadioButtonList()
    {
    }


    protected override void RenderItem(ListItemType itemType, int repeatIndex, RepeatInfo repeatInfo, HtmlTextWriter writer)
    {
    if (itemType == ListItemType.Item ||
    itemType == ListItemType.AlternatingItem ||
    itemType == ListItemType.EditItem ||
    itemType == ListItemType.SelectedItem)
    {
    writer.AddAttribute("onmouseover", "foo");
    writer.AddAttribute("onmouseout", "bar");

    ListItem item = Items[repeatIndex];

    item.Attributes.AddAttributes(writer);
    if (!item.Enabled)
    writer.AddAttribute(HtmlTextWriterAttribute.Disabled, "true");
    if (item.Selected)
    writer.AddAttribute(HtmlTextWriterAttribute.Checked, "true");
    writer.AddAttribute(HtmlTextWriterAttribute.Value, item.Value);
    writer.AddAttribute(HtmlTextWriterAttribute.Type, "radio");
    writer.RenderBeginTag(HtmlTextWriterTag.Input);
    writer.Write(item.Text);
    writer.RenderEndTag();

    return;
    }

    base.RenderItem(itemType, repeatIndex, repeatInfo, writer);
    }

    }
    }


    --
    John Saunders
    johnwsaundersiii at hotmail

    "Jay" <> wrote in message news:%...
    No. I do call base.render. Base.render will display the original radiobuttonlist. The only way to add mouseover events to the individual options is to redo the render method entirely.

    Jay
    "John Saunders" <> wrote in message news:...
    Are you calling base.Render when you're done with your code?

    --
    John Saunders
    johnwsaundersiii at hotmail

    "Jay" <> wrote in message news:...
    I have subclassed RadioButtonList to add the mouseover and mouseout events to individual options. As far as I can see I have to totally rewrite the render method. The way I did it I have not included any inherited styles and properties. How do I inherit the styles and properties that have been set by the developer. I can add styles by using AddStyleAttribute. I can also determine what styles have been set using Me.style.keys and then add them using AddAtyleAttribute. Seems like there should be a way to add all at once all the styles that are inherited. Similarly, I cannot figure out how to add properties like Forecolor all at once.

    I tried to override AddAttributesToRender but i do not seem to ever execute that method.

    Help?

    Jay
     
    John Saunders, Jul 27, 2004
    #4
    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. Lanmind
    Replies:
    12
    Views:
    654
    Lanmind
    Sep 8, 2008
  2. Ken Varn
    Replies:
    0
    Views:
    504
    Ken Varn
    Apr 26, 2004
  3. Dann Pool
    Replies:
    0
    Views:
    120
    Dann Pool
    Nov 11, 2003
  4. Replies:
    12
    Views:
    332
    Robert Mark Bram
    Dec 3, 2004
  5. Benjy Borda

    Inheriting Data Properties

    Benjy Borda, Jul 4, 2009, in forum: Javascript
    Replies:
    12
    Views:
    151
    Thomas 'PointedEars' Lahn
    Jul 17, 2009
Loading...

Share This Page