0

I'm creating a panel in order to fill it up with some controls but i got error when i try to write its properties.

My code:

public partial class _Default : System.Web.UI.Page
{

      Panel pbx;
        protected void Page_PreInit(object sender, EventArgs e)
        {
            //Create a Dynamic Panel
            pbx = new Panel();
            pbx.ID = "pbx";
            pbx.BorderWidth = 1;
            pbx.Width = 300;
            this.form1.Controls.Add(pbx);
        }

//some other functions
}

Visual Studio 2012 underlines "ID", "BorderWidth" and "Width" words, so i cant run the project. one of errors is like this:

'simplePanel.Panel' does not contain a definition for 'BorderWidth' and no extension method 'BorderWidth' accepting a first argument of type 'simplePanel.Panel' could be found (are you missing a using directive or an assembly reference?)

edit: I can create a textbox or label with no problem. But not a panel.

2 Answers 2

2

There is a class called simplePanel.Panel which conflicts with System.Web.UI.WebControls.Panel (which I assume is what you are trying to reference). If your _Default class is in the simplePanel namespace as well, then you need to fully qualify the references to Panel so that the compiler knows which one you mean:

public partial class _Default : System.Web.UI.Page
{
    System.Web.UI.WebControls.Panel pbx;
    protected void Page_PreInit(object sender, EventArgs e)
    {
        //Create a Dynamic Panel
        pbx = new System.Web.UI.WebControls.Panel();
Sign up to request clarification or add additional context in comments.

3 Comments

that didn't work. i paste your code at the top but nothing changed.
@AliSağırvelioğulları: Is your _Default class inside a namespace, or is public partial class _Default really the first line in the file?
it's in simplePanel namespace.
0

Set the width like this:

pbx.Width = new Unit("300px");

It will help you out to cover the situation.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.