How do I call my class file?

  • Thread starter Thread starter Charles
  • Start date Start date
C

Charles

Hello,
I have created a class file: Admin.cs with a namespace
of cs101.Code.nsAdmin.

From my ASP page: Login.aspx.cs how do I reference
Admin and then execute one of its methods
"public DataRow RetrieveUserbyUserNameNPassword(string
userName, String password)" ?
Charles
 
You include it's namespace in Login.aspx.cs

using cs101.Code.nsAdmin;

then you call the methods in Admin.cs

cs101.Code.nsAdmin.Method1();

A better way for long namespaces would be to use aliasing

using Admin = cs101.Code.nsAdmin;
Admin.Method1();
 
In your case, it would be (provided you use Admin as an alias for
cs101.Code.nsAdmin)

DataRow row = Admin.RetrieveUserbyUserNameNPassword(username, password);
 
Hello,

I did:

using cs101.Code.nsAdmin;
at the top of Login.aspx.cs

and:
DataRow drUser =
cs101.Code.nsAdmin.Admin.RetrieveUserbyUserNameNPassword( UserName.Text,
Password.Text );

inside my click event, the error I get is:
"An object reference is required for the nonstatic field, method, or
property
'cs101.Code.nsAdmin.Admin.RetrieveUserbyUserNameNPassword(string,
string)'

what did I do wrong?
 
Hi Charles,

Is your RetrieveUserbyUserNameNPassword method a non-static method member
of a certain class?
If it is, you should create a instance of this class and use this
new-created object to call this method.

Hope this helps,
Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

--------------------
| From: Charles Wildner <[email protected]>
| References: <oprvulvjqrge0n9a@localhost>
| X-Newsreader: AspNNTP 1.50 (ActionJackson.com)
| Subject: Re: How do I call my class file?
| Mime-Version: 1.0
| Content-Type: text/plain; charset="us-ascii"
| Content-Transfer-Encoding: 7bit
| Message-ID: <[email protected]>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Date: Sun, 21 Sep 2003 07:43:05 -0700
| NNTP-Posting-Host: actionjackson133.dsl.frii.net 216.17.147.133
| Lines: 1
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTNGP11.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:186335
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Hello,
|
| I did:
|
| using cs101.Code.nsAdmin;
| at the top of Login.aspx.cs
|
| and:
| DataRow drUser =
| cs101.Code.nsAdmin.Admin.RetrieveUserbyUserNameNPassword( UserName.Text,
| Password.Text );
|
| inside my click event, the error I get is:
| "An object reference is required for the nonstatic field, method, or
| property
| 'cs101.Code.nsAdmin.Admin.RetrieveUserbyUserNameNPassword(string,
| string)'
|
| what did I do wrong?
|
|
|
|
| Don't just participate in USENET...get rewarded for it!
|
 
Back
Top