locked
I want only ONE instance of a style property but user allowed to code multiple? RRS feed

  • Question

  • User1227920254 posted

    I have a style in my server control. I want the user to be able to code only one instance, kind of like TemplateInstance(TemplateInstance.Single) acts on a template property, but I want same behavior for my custom style. What attribute am I missing? Here is my code...

     

     

    // The user is allowed to code multiple <HeaderStyle> properties, but I want to limit them to only ONE instance!
    
    [
    		Category("Styles"),
    		Description("The style to be applied to the Header of this control."),
    		MergableProperty(false),
    		PersistenceMode(PersistenceMode.InnerProperty),
    		RefreshProperties(RefreshProperties.All),		
    		]
    		public HeaderStyle HeaderStyle {
    			get {
    				if (m_headerStyle == null) {
    					m_headerStyle = new HeaderStyle();
    				}
    				if (IsTrackingViewState) {
    					((IStateManager)m_controlState).TrackViewState();
    				}
    				return m_headerStyle;
    			}
    
    			set { 
    				m_headerStyle = value;
    				ChildControlsCreated = false;
    			}
    		}
      
    Tuesday, July 29, 2008 10:06 AM

Answers

  • User481221548 posted

    Hi Gene

    I understood.
    The best practice is to use pure CSS (Cascading Stylesheets) for that.

    If you want to use the ASP.NET "HeaderStyle" Stuff, you could programming a loop throught all Controls and set the Style programmatically.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 4, 2008 3:50 PM

All replies

  • User1477435862 posted

    Gene, I can't find anything that would allow you to do that.  I think you're just going to have to live with it, i'm afraid. [:(] 

    Friday, August 1, 2008 9:15 AM
  • User481221548 posted

    Hi Gene

    Why not use coding a loop to apply your Style to all Partitions?

    Monday, August 4, 2008 12:52 PM
  • User1227920254 posted

    Hi Gene

    Why not use coding a loop to apply your Style to all Partitions?

     

     I guess I do not understand. Currently, intellisense shows <HeaderStyle> as I type my code, even though I have already coded a previous <HeaderStyle>. I do not want this; I want the behavior to act as stated earlier in the post. How is a "loop" going to do this?

    Monday, August 4, 2008 2:16 PM
  • User481221548 posted

    Hi Gene

    I understood.
    The best practice is to use pure CSS (Cascading Stylesheets) for that.

    If you want to use the ASP.NET "HeaderStyle" Stuff, you could programming a loop throught all Controls and set the Style programmatically.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, August 4, 2008 3:50 PM
  • User1227920254 posted

    Hi Gene

    I understood.
    The best practice is to use pure CSS (Cascading Stylesheets) for that.

    If you want to use the ASP.NET "HeaderStyle" Stuff, you could programming a loop throught all Controls and set the Style programmatically.

     

    Sorry, but I still don't know if we are on the same page...just making sure...because you're still loosing me...

    The code snippet provided is from one of my custom server controls; my property, "HeaderStyle" (call it whatever you want), does render as "pure CSS" and gives the user the ability to customize the control's style in code-view, or, via Theme regardless of how the control is rendered. Depending on other properties the user chooses, the control can render differently. I think it would be painful for a user of my control to be forced to (or even want to) provide their own css as they would have to read through the rendered code AND HOPE AND PRAY that noone chooses an option that would cause it to render differently. The way I am doing it will give them that option anyhow. I am not saying that Microsoft always follows "best practices" however, the model I am trying to provide seems to mimic many useful Server Control available in .Net (Login, Gridview, to name a few).

    Are you saying I should just provide a HeaderCssClass property and let the user supply a .css file?

    You sure we're on the same page?

     

     

     

     

    Monday, August 4, 2008 4:40 PM
  • User481221548 posted

    Hi Gene

    We`re on the same Page for sure.
    As i wrote, you can set your Style-Properties (the one where produce inline css) programmatically instead of set one by one.

    Maybe Skins are for you?

    Monday, August 4, 2008 6:01 PM
  • User1227920254 posted

     Can't visualize this...perhaps I am a dolt...do you have a simple example lying around?

    Tuesday, August 5, 2008 8:49 AM
  • User481221548 posted

    Hi Gene

    Search Keyword: asp.net skins / control skins

    Example?
    Loop to the Styles-Collection and set your value to each of them, this is easy.

    Tuesday, August 5, 2008 6:42 PM