Learn how to a build a cloud-first strategyRegister Now


'System.Drawing.Color.Red.get' cannot be accessed

Posted on 2006-04-12
Medium Priority
Last Modified: 2012-06-27
i have converted code from vb to c# and im getting this error, how do i get rid of this:

 public void ControlToHighlight(string ControlType, string ControlId)
        TextBox oControlTextbox;
        DropDownList oControlDropDown;
        CheckBoxList oCheckBoxList;
        RadioButtonList oRadioButtonList;
        Label oLabel;
        Panel oPanel;
        if (ControlType.Length > 0)
            if (ControlType == "textbox")
                oControlTextbox = ((TextBox)(FindControl(ControlId)));
                if ((!(oControlTextbox == null)))
                    oControlTextbox.BackColor = oControlTextbox.BackColor.Red;   <<<<<<<<error
                    oControlTextbox.ForeColor = oControlTextbox.ForeColor.White; <<<<<<<<error

error message is:

Error      1      Static member 'System.Drawing.Color.Red.get' cannot be accessed with an instance reference; qualify it with a type name instead      App_Code\webPagebase.cs      49      50      
Question by:madina1
  • 2
LVL 39

Accepted Solution

appari earned 200 total points
ID: 16441762
try changing

oControlTextbox.BackColor = oControlTextbox.BackColor.Red;   <<<<<<<<error
oControlTextbox.ForeColor = oControlTextbox.ForeColor.White; <<<<<<<<error


oControlTextbox.BackColor = System.Drawing.Color..Red;  
oControlTextbox.ForeColor = System.Drawing.Color..White;

Author Comment

ID: 16441784
before i post it, i did the exact thing and then i thought im not doing correct so that correct?
LVL 39

Expert Comment

ID: 16441796
yes its correct, try it and see the results

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question