Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

.NET Inherited Control

  • 25-07-2011 03:06PM
    #1
    Registered Users, Registered Users 2 Posts: 527 ✭✭✭


    Hi all,

    I have created a very simple custom control:
    [assembly: System.Web.UI.TagPrefix("CustomMultiLineTextBox", "evo")]
            public class CustomMultiLineTextBox : 
                System.Web.UI.WebControls.TextBox
            {
    
                public override int Rows
                {
                    get
                    {
                        return 5;
                    }
                }
    
                public override System.Web.UI.WebControls.TextBoxMode TextMode
                {
                    get
                    {
                        return System.Web.UI.WebControls.TextBoxMode.MultiLine;
                    }
                }
        public override string CssClass
                {
                    get
                    {
                        return "textboxStyle";
                    }
                    set
                    {
    //base.CssClass = "textboxStyle";
                        base.CssClass = value;
                    }
                }
            }
            }
    

    However, when I drop this control onto my aspx page the CssClass does not seem to be applied. The TextMode and Rows property are set correctly.
    <evo:CustomMultiLineTextBox ID="txtTrainingNeeds" runat="server">
    </evo:CustomMultiLineTextBox>
    

    Only if I add CssClass="textboxStyle" to the markup will the CssClass be applied.

    Any suggestions?

    Thanks in advance


Comments

  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭John_Mc


    What happens if you leave CssClass=""? Maybe the textbox control requires that the cssclass property isn't null?


  • Registered Users, Registered Users 2 Posts: 527 ✭✭✭Sean^DCT4


    Hi John,

    Thanks for the suggestion. I was thinking that earlier on this morning and that didn't work when I left it empty..

    Just, added this and removed the override on the CssClass and it worked:
    public CustomMultiLineTextBox()
    {
        CssClass = "textboxStyle";
    }
    


  • Registered Users, Registered Users 2 Posts: 2,793 ✭✭✭John_Mc


    Sean^DCT4 wrote: »
    Hi John,

    Thanks for the suggestion. I was thinking that earlier on this morning and that didn't work when I left it empty..

    Just, added this and removed the override on the CssClass and it worked:
    public CustomMultiLineTextBox()
    {
        CssClass = "textboxStyle";
    }
    

    That's strange! Must be a IsNullOrEmpty check instead of just a null check.

    Edit: sorry, just saw the CSS at the top!


Advertisement