New to C#

Need help with where to place files

Page 1 of 1

7 Replies - 1125 Views - Last Post: 16 March 2010 - 08:38 PM Rate Topic: -----

#1 k1n6   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-March 10

New to C#

Posted 15 March 2010 - 12:27 AM

Hi All,

I want to write a really simple C# object and have an .aspx page call a function from that object and return content to the page.

I am really familiar with OOP but can not find how to do this.

1) Where do I put the C# class file in my web app so it will find it when I try to Instantiate it?
2) Is there any additional stuff I need to add to my web.config in order instantiate this class from my .aspx file?

I don't use visual studio, so I'm assuming I can upload source to the server and it compiles it just in time, right?

Ultimately I'd like to just create a csc file, dump it in the folder my .aspx file is in, invoke the .csc in the .aspx and then call a function from it.

Thanks in advance,
Dan

Is This A Good Question/Topic? 0
  • +

Replies To: New to C#

#2 SwiftStriker00   User is offline

  • No idea why my code works
  • member icon

Reputation: 439
  • View blog
  • Posts: 1,617
  • Joined: 25-December 08

Re: New to C#

Posted 15 March 2010 - 06:25 AM

I very much suggest that you do use Visual Studio or some other C# IDE. They will usually handle these things. As for your C# class, you can put it anywhere really, as long as you reference it properly. Fore example if i have a folder call MyProject, and i put MainClass.cs in there, that class is my client, and i put a folder in there too call "code." Now in the code folder I create MyObject.cs. This means when I use MyObject in the MyProject i have to do something like using code.MyObject. in order to get the path correct.
Was This Post Helpful? 0
  • +
  • -

#3 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: New to C#

Posted 15 March 2010 - 07:11 AM

Moving to ASP.Net
Was This Post Helpful? 0
  • +
  • -

#4 k1n6   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-March 10

Re: New to C#

Posted 15 March 2010 - 08:54 AM

Thanks for the help so far.

But when I try to use a "using" statement in my aspx file it doesn't like that. How do I then invoke the CS file from the aspx?

Is there any way I can alter the default aspx environment to have a set of using statements?

That would remove the need for the separate class altogether as then I can call the code directly from the .aspx without having the class file (which has a series of dependencies and uses a bunch of using statement).

Dan
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1536
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: New to C#

Posted 15 March 2010 - 09:40 AM

I am going to tell you the truth. I think you are going to have a very hard time finding someone who didn't use Visual Studio to publish an ASP.Net website.
Was This Post Helpful? 0
  • +
  • -

#6 k1n6   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-March 10

Re: New to C#

Posted 15 March 2010 - 04:18 PM

So the proliferation of this tool has removed the knowledge of how to place these elements?

Seems so odd to me coming from numerous other languages, including java, that you can just put your class files in a classpath of some kind, invoke them, and then call functions from them as you see fit.

I guess I'll re-consider my options here. It's either download the 800 meg beast that is visual studio or rewrite in a language with less entry barrier.

This post has been edited by k1n6: 15 March 2010 - 04:19 PM

Was This Post Helpful? 0
  • +
  • -

#7 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: New to C#

Posted 15 March 2010 - 05:43 PM

View Postk1n6, on 15 March 2010 - 07:54 AM, said:

Thanks for the help so far.

But when I try to use a "using" statement in my aspx file it doesn't like that. How do I then invoke the CS file from the aspx?

Is there any way I can alter the default aspx environment to have a set of using statements?

That would remove the need for the separate class altogether as then I can call the code directly from the .aspx without having the class file (which has a series of dependencies and uses a bunch of using statement).

Dan


How are you coding the 'using' or Import statement on the ASPX page? Is it in a script tag?

You don't have to have a CS file to contain the code, you can put it all on the ASPX page. You just need to enclose it in script tags, so that the server knows what is server side and what should be dished up to the client.

There is an example in this Wiki article, Pages section, that shows the code on the ASPX page.

Here is an example of how to import on the ASPX page.
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>

Was This Post Helpful? 2
  • +
  • -

#8 k1n6   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 15-March 10

Re: New to C#

Posted 16 March 2010 - 08:38 PM

Thank you, Jayman the import statements were exactly what I was looking for.

I was able to get some code snippet I found running flawlessly as a result.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1