Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

.NET Inherited Control

Options
  • 25-07-2011 3:06pm
    #1
    Registered Users 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 Posts: 2,791 ✭✭✭John_Mc


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


  • Registered Users 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 Posts: 2,791 ✭✭✭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