locked
Overriding Visibility on Custom Server Control RRS feed

  • Question

  • User381432427 posted

    I'm creating a custom server control, and am having trouble overriding the visibility property.  What I would like to do is to override the property and set the value to a private bool that I can then check against.  If the control is then set to false, I'd like to run a chunk of code that inserts some javascript our master page needs to compensate for the missing control while still preventing the markup from rendering.  For whatever reason it seems my private bool is being set properly in the override get/set but the control still shows respects the visible=false request and nothing is rendered to the browser.  I'm currently leaning towards trying to disable this property all together and coming up with my own custom property to handle this, but was hoping there may be an easier way.

    Tuesday, April 14, 2009 9:15 AM

Answers

  • User1186257875 posted

    try this

    override the Visible property with following Property level Attributes..

    set Browsable attribute to False. so that this property is not be visible in Property window.

    [Browsable(false)]

    then make this propety read only by adding only get method. (if user try to set the Visible property from code behind, he is not able to set because property is read only)

    read about [ReadOnly(true)] attribute

    then write your own custom prooperty for visibility.

    That is only for IDE enhancements! You are still able to set the property in code or markup :)
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 20, 2009 5:39 AM

All replies

  • User1186257875 posted

    Hey Wigmo,

    You could hide the property and then override render to output something (i.e. <p>this control is hidden</p>).

    Perhaps like so?

    public new bool Visible

    {

    get; set;

    }

    protected override void Render(HtmlTextWriter writer)

    {

    if (Visible)

    {

    base.Render(writer);

    }

    else

    {

    writer.Write(
    "Control Hidden");

    }

    }

     

    Tuesday, April 14, 2009 9:57 AM
  • User381432427 posted

    That's the direction I wanted to take when I started, and that will step through the code just fine but the condition I have in the else condition still will not write out.  Blah.  So now I am looking into how to disable the visible property and use my own custom properties instead.

    Friday, April 17, 2009 9:11 AM
  • User1306565749 posted

    Hi,

    try this

    override the Visible property with following Property level Attributes..

    set Browsable attribute to False. so that this property is not be visible in Property window.

    [Browsable(false)]

    then make this propety read only by adding only get method. (if user try to set the Visible property from code behind, he is not able to set because property is read only)

    read about [ReadOnly(true)] attribute

    then write your own custom prooperty for visibility.

     

    Monday, April 20, 2009 2:12 AM
  • User1186257875 posted
    So now I am looking into how to disable the visible property and use my own custom properties instead
    That is what it is doing! The new keyword means it is hiding the original property! It defiantly does work on my machine! Could you copy and paste the code that is not working!?
    Monday, April 20, 2009 5:35 AM
  • User1186257875 posted

    try this

    override the Visible property with following Property level Attributes..

    set Browsable attribute to False. so that this property is not be visible in Property window.

    [Browsable(false)]

    then make this propety read only by adding only get method. (if user try to set the Visible property from code behind, he is not able to set because property is read only)

    read about [ReadOnly(true)] attribute

    then write your own custom prooperty for visibility.

    That is only for IDE enhancements! You are still able to set the property in code or markup :)
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, April 20, 2009 5:39 AM
  • User381432427 posted

     I'm just now getting back into this.  I was able to accomplish what I wanted by just avoiding the visible property all together, although I am now able to set visible to false and still have my contents render (not really sure what was going on the other day).  At this point I thought about hiding visiblity but I think I will integrate that into my existing logic and have that overule the custom property I created.  It's either that or just try to hide the property from the designer.  Thanks for the help.

    Wednesday, April 22, 2009 8:52 AM