Posts Tagged ‘C#’

Jul
06/09
C# Missing References
Last Updated on Monday, 6 July 2009 05:08
Written by snapjag
Monday, July 6th, 2009

If you are getting an error like “The type or namespace name does not exist in the namespace” you may have found yourself tweaking the references or the using statements in your C# code.

The using statement and the referencing statement differ in that the using statement is a logical link and reference to the namespace library, this makes it so you can shorten your qualifications to objects. Instead of typeing System.Windows.Forms.Textbox. You place a using statement “using System.Windows.Forms” at the top of your page and you only have to now use the word Textbox to reference the object. These are also usually statements to libraries within your current namespace.

The References are registrations to libraries and dlls that are to be used outside your namespace.

Recently in a project, there were a number of projects that had change adding some ENUM references that were prominently used in the application. These errors made it immpossible to build the solution. In order to rid yourself of this error, you must resolve a conflict, or supply a reference or using statement.

First, check the statement where the error occurs. Make sure the namespace/library that the object refers to is available in the project. If you find the source cs file, look to see if the Namespace is different than where the object is being used. If they are different, then either fully qualify the namespace in front of the object, or add the “using <full namespace>;” statement at the top.

Try and compile the application, if you still have the error, then look in the current project (where the error occurs) References list and see if the assembly/library is there. It’s it isn’t, then add the new Reference by either locating the .NET object, COM object, project, or file.

When this has been added, try compiling again. If you still get the error, then you’ll have write some comments here and provide your code for me to be able to help you further.

Tags: , , , , ,   |  Posted under Programming  |  Comments  No Comments
Apr
23/09
Using properties in an ASP.net Web Control
Last Updated on Thursday, 23 April 2009 02:49
Written by snapjag
Thursday, April 23rd, 2009

When creating a web control in an ASP.net application many times you will need to make references to information, data values and other contents of the web control from the web control parent. This is done by adding a Property statement on the control. It could be as simple as a Username and Password control to set or get the information at times of requesting login details.

Follow these steps to connect and use data on the User Web Control:

  1. Create a new Web Control in your application project
  2. Place two label and two textboxes on the control
  3. Name the two controls txtUsername and txtAddress
  4. In the code behind of the control add the following code (C#)private string username = String.Empty;
    private string password; = String.Empty;
  5. public string Username {
    get { return username; }
    set { set username = value; }
    }

    public string Password{
    get { return password; }
    set { set password; = value; }
    }

  6. Close the control designer windows, saving all changes
  7. Open the web page that will use the control
  8. Drag and drop the new web control onto the web page canvas (if you already had the web control on your webpage and you added new interface elements (public functions or properties), you will likely need to remove the controls including the REGISTER statements at the top of the page so that the interface elements are reconnected to the page for you.
  9. In the code behind the web page, make any references to the Tag name of the control (assuming “uc1″ in this case) using the following statements (C#).this.uc1.Username = “Your username”;
    this.uc1.Password{ = “Your password”;

This concludes the tutorial to add a simple web control and connect to it from the parent web page where it resides. This concept will help in many ways like, login pages, bread crumbs, contained lists, or other user interface lists.

Tags: , , , ,   |  Posted under ASP.NET, Programming  |  Comments  No Comments