.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

class names and namespace behaviour

Posted By:      Posted Date: September 06, 2010    Points: 0   Category :ASP.Net
This is something that I'm not sure if it's a problem or something I have configured wrong. Just thinking on it is making my head hurt!! So here goes. What I'm doing...   1. create a blank VS2010 web project called "MySite" targeted at 4.0 2. create a new class object, calling it "class1.vb" (cause it's so unique!!) 3. change default code to read as such...Namespace MySite Public Class Functions Public Shared Function WhatIsTodaysDate() As String Return Date.Now.ToLongDateString End Function End Class End Namespace 4. create a new webform and drop a label control on it. In the page_load event, I want to set the label to equal the value of Function WhatIsTodaysDate. Simple enough, but now comes the part that escapse me. I can do this...Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Label1.Text = MySite.Functions.WhatIsTodaysDate() End Sub but if I want to shorten my code, and call the function using an "Imports" tag i have to do this...Imports MySite.MySite.Functions Public Class WebForm1 Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Label1.Text = WhatIsTodaysDate() End Sub End Class Why is VS asking me to call the namespa

View Complete Post

More Related Resource Links

Error trying to extend a class, The type or namespace name 'ErrorData' does not exist in the names


I would like to create a class that extends my ErrorData class, i have not done this in a while and when i try    class ErrorDataASPX : ExceptionHandler.ErrorData and build i get msg:

Error 1 The type or namespace name 'ErrorData' does not exist in the namespace 'ExceptionHandler' (are you missing an assembly reference?) C:\ExceptionHandling\ExceptionHandler\ErrorDataASPX.cs 9 44 ExceptionHandler

namespace ExceptionHandler
    class ErrorDataASPX : ExceptionHandler.ErrorData

namespace ExceptionHandling
    using System;
    using System.Globalization;
    using System.Text;
    using System.Web;

    /// <summary>
    /// Contains information about an error.
    /// </summary>
    public class ErrorData

Class Templates: Bring the Power of Templates to Your .NET Applications with the CodeDOM Namespace


In the .NET Framework, the CodeDOM object model can represent code in a variety of languages. This article examines how source code templates written with the Framework's System.CodeDom and System.CodeDom.Compiler namespaces allow developers to create reusable boilerplate source code that can be shared between projects. Components designed via templates improve productivity and shorten development time.Here C++-style classes and templates are simulated and code is generated in multiple languages through the creation of CodeDOM object graphs. Compiling object graphs and formatting output code are also explained.

Adam J. Steinert

MSDN Magazine February 2003

How do I find the file path from a namespace.class name?


I'm programatically looking ito a .aspx file and getting the file class name declared in its CodeBehind. For example, when analyzing myFile.aspx I read in its Page Directive and found its CodeBehind equals "myApplication\myPage.aspx.vb". Then I use the code below:


Dim Assm As System.Reflection.Assembly = System.Reflection.Assembly.LoadFrom("myApplication\bin\myApplication.dll")
Dim ClassType As Type = Assm.GetType("myApplication\myPage.aspx.vb")
' myBaseType = "myApplication.Forms.BasePage"
Dim myBaseType As System.Type = ClassType.BaseType


Now I want to read the BaseFile (class = myApplication.Forms.BasePage). However, to read in this file, I need I need to get its full path instead of its namespace.class hiearchy. In this case, the BasePage is wrapped in a different namespace declaration thus I cannot just change the '.' to '\' in order to get the path.

How can I get the path of BasePage so I can read it? Thank you - Frank

How can I access a webform control from another external class/namespace?


Currently, I have many controls and objects such as Chart1 of mschart as part of the public partial class _Default : System.Web.UI.Page.

At the bottom, I've created a second class that is not part of the _Default webform class.  How can I access the webform controls from this second class?

For example, I want to do

Chart1.Series["Series1"].Points.AddXY((pointIndex + 1) * 40, datapoints[pointIndex]);

I want to pass pointIndex integer and the datapoints array.

I know that Chart1 was created protected global access modifier in the designer.cs but when I changed it to public, it still had a problem.


modification in class shows namespace error


hi all,

this code i copied from http://www.csharp-station.com/Tutorials/Lesson07.aspx

using System;

class Address
    public string name;
    public string address;

  class MethodParams
    public static void Main()
        string myChoice;

        MethodParams mp = new MethodParams();

            // show menu and get input from user
            myChoice = mp.getChoice();

            // Make a decision based on the user's choice

            // Pause to allow the user to see the results
            Console.Write("press Enter key to continue...");

New public class in namespace (web service, asmx)



I have a working web service written in C#.NET that was set up by my predecessor, and have been able to successfully modify it in the past. It works without problems in production.

Basically, the service takes XML code and sends it to a postURL with an outside vendor API. They send back an XML document that we then parse out.

My issue is that I need to connect to another vendor API concurrently with the existing one.

Method 1) Should I create an entirely new Web Service for the new vendor? I tried this but there seemed to be an issue with the ports, having them run at the same time. Should I try again? Any port secrets?

Getting stuck on Method 1, I'm on to Method 2 now....

Method 2) Modifying the exiting web service by adding a new public class to the namespace. I also modified the wsdl, disco and discomap files for the new service. It did compile, but something is missing.

Service1 = exisiting, working web service

https://servername/Service1.asmx - works beautifully and lists all my API calls

https://servername/Service1.aspm?wsdl - shows my wsdl file

Service2 = new, copied web service

baffling issue in TailSpin Tutorial -- class namespace changed


In Tailspin Spyworks tutorial #5 Building Business Logic http://www.asp.net/web-forms/tutorials/tailspin-spyworks-part-5

Here is the excerpt from the tutorial pg 38 of the full pdf

The class file that we just generated looks like this.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace TailspinSpyworks.Classes
      public class MyShoppingCart

We will merge our implementations by adding the partial keyword to this file as well.
Our new class file now looks like this.

   namespace TailspinSpyworks.Classes
         public partial class MyShoppingCart

However....in the download the namespace is actually "namespace TailspinSpyworks" without the .Classes

Here is the code from the download

namespace TailspinSpyworks
    public struct ShoppingCartUpdates
        public int ProductId;
        public int PurchaseQantity;
        public bool RemoveItem;

    public partial class MyShoppingCart
        public const string CartId = "TailSpinSpyWorks_CartID";


How can I rename the storedprocedure names SqlMembershipProvider class?


I understand SqlMembeshipProvider calls stored procedures with 'dbo' extension 
(example - dbo.aspnet_CheckSchemaVersion). I want to change this in my ASP.NET code.
How can I override the SqlMembershipProvider Class and change the name of the stored 
procedures in the class to 'myusername.aspnet_....'?

I understand SqlMembeshipProvider class calls stored procedures with 'dbo' extension (example - dbo.aspnet_CheckSchemaVersion). I want to change this in my ASP.NET code. How can I override the SqlMembershipProvider Class and change the name of the stored procedures in the class to 'myusername.aspnet_....'?


Export Visio Database Table Names to Excel

If you use the Enterprise Architect edition of Microsoft Visio for data modeling regularly, then there is a good chance that at some point you've wanted to export just the table names into Excel. You might want to do this to map logical ERD entities to physical data model tables, track project status by entity, or track overlap between database versions.

Class Diagrams

Class diagrams show the static structure of the systems. Classes define the properties of the objects which belong to them. These include:

Attributes - (second container) the data properties of the classes including type, default value and constraints.

Creating a Simple Class in C#

The second article in the C# Object-Oriented Programming tutorial describes how classes are created in C# and how behaviour, in the form of publicly visible and private, hidden methods can be added. This demonstrates some of the uses of encapsulation

Static Class for Beginners

In general, the members of a class can be accessed by instance of that class when they are in public, but there comes a situation to access or call members of a class without an instance and this can be achieved by declaring them as static

abstract away the source of the connection string using a class with a static property.

ASP.NET provides a configuration system we can use to keep our applications flexible at runtime. In this article we will examine some tips and best practices for using the configuration system for the best results.

The element of a web.config file is a place to store connection strings, server names, file paths, and other miscellaneous settings needed by an application to perform work. The items inside appSettings are items that need to be configurable depending upon the environment, for instance, any database connection strings will change as you move your application from a testing and staging server into production.

Let's abstract away the source of the connection string using a class with a static property.

MessageQueue Class

This sample demonstrates two way communications using message queuing between a device application and a desktop application. One application sends book order messages to a message queue and another application receives these book orders from the message queue and responds to the device queue that the orders have been processed.

Type or namespace error.


A couple of days ago I started getting an unusual behavior when compiling Website projects. I have referenced class libraries added to my bin folder that are also correctely referenced in using statements in my aspx.cs code behind. When I compile, I get the 

Error 4 The type or namespace name 'CommonClassLibrary' could not be found (are you missing a using directive or an assembly reference?) C:\Dev\Fiscal_Portal\Implementation\FMS Portal Site_new\App_Code\BLL\DataTables.cs 1 7 C:\...\FMS Portal Site_new\

The type or namespace name 'CommonClassLibrary' could not be found (are you missing a using directive or an assembly reference?)

error message that would typically be received when the dll has not been added as a reference or added in a using statement.

I can eliminate the error by adding an


How to change the default page base class?


I've tried setting the <pages pageBaseType="DynamicWebPage" /> value in web.config, but when I response.write out the page type, I'm still getting Microsoft.WebPages.WebPage.

I'm simply trying to sub-class WebPage and add some additional functionality such as a dynamic PageData dictionary similar to Phil Haack's dynamic ViewData dictionary.



Creating A Stored Procedure Which Searches Team Names



I'm have on my web page a text search box which I want users to type in there favourite football team and this will display a gridview of the teams with the replica shirts I offer.

This is where I thought about creating a stored procedure to carry out this task.

I looked online for ideas but I not found anything as yet.

If anyone done anything similar to my request please let me know.

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend