SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Learning (VS Web Dev Express) building the website

    I am fresh as a baby to ASP.NET. Apologies for what you probably find a rediculous question.

    I have a Web Site open in VS (visual studio express). I have been playing with form control and events in the code behind for some time and all is well. Building the website works fine.

    The problem I have now though is I have created a class (.cs) (using file add new item). I wish to use the class in the code behind file.

    For the life of me I can't work out how to do this. All tutorials online seem to work with the code behind file only and never add their own classes.

    To a fresh web site how would I
    1) create a class?
    2) use the class and access it in default.aspx.cs
    3) build the website

    Please can some one help?

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    1) ASP.NET sites have a construct whereby you can put your code in a folder called "App_Code", which will then get compiled into classes. This works fine for smaller applications, which we are dealing with here. For larger-scale stuff, you will generally put your class files in a separate library project and reference that project. But putting the .cs file in App_Code should work for now.

    2) Once it is in App_Code, you should just be able to create a new instance of the class (eg: Foo f=new Foo();) and then access methods & properties (eg: f.DoSomething(someString);). Your class is, in fact, fundamentally no different than any of the classes you have been dealing with on web forms.

    3) Right click on website in the solution explorer and choose build. It should also be on the build menu. As for deploying the website, I am not to familiar with the express editions, but I think there is a deployment wizard. The best option would be to deploy to your local filesystem, choosing the "create static assemblies" option. Then FTP that set of folders and files up to your host.

  3. #3
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Cheers, right after I posted I created another class and this time read the alert that is displayed on creation about the App_Code folder.

    All is well and it seems to work fine. No NameSpaces used.

    What is the benefit in creating classes in a library project and referencing it? Am I right in saying this can't be done in Visual Studio Express?

    On top of that at this moment in time I am not using namespaces on the classes in the App_Code directory. Is it beneficial to do so?

    When should you do all this neat organising etc etc?

    Thanks for your reply BTW. Appreciated.

  4. #4
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    I think you can create class libraries in VS Express, but I might be wrong. I really have zero experience with it save deployment to a few folks as a stopgap whysiwig HTML editor.

    Main advantage of creating a class library project is that it can be referenced by things other than your web application. For example, the core business logic and data access libraries I use in most project are shared between one or more web applications and oftentimes one or more command line applications.

    When should you organize? When you cease to be able to find things is the short answer. Though a bit of project planning up front is never a bad thing.

  5. #5
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think you can create class libraries with Visual Web Developer, you can with VB.NET Express and C# Express.

    As for when to organise, I think I differ from Wyatt slightly on this. I like to spend a good amount of them with diagrams and UML, very much blueprint over sketch.

  6. #6
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    dhtmlgod, what do you mean by
    I like to spend a good amount of them with diagrams and UML, very much blueprint over sketch.
    wwb 99, what you mean by
    with it save deployment to a few folks as a stopgap whysiwig HTML editor.

  7. #7
    ALT.NET - because we need it silver trophybronze trophy dhtmlgod's Avatar
    Join Date
    Jul 2001
    Location
    Scotland
    Posts
    4,836
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Any project should have some pre-code design stage, this allows yourself and any other developers to have at least a small image of the bigger picture and what the aims of the project are. There are two general "modes" for this, sketch and blueprint.

    The sketch mode is a loose mode, where a birds eye view of things are generally used, and maybe complex parts fleshed out a little more.

    The blueprint mode is alot more strict, with more details on the over all processes involved within the project and code.

    ( disclaimer: the above is IMO, I could be incorrect and stupid )

    I use blueprint because I like to have everything mapped out before I lay any code down. I generally find this allows me to break it up easier into milestones, and allows me to develop different parts of different systems before others, basically allowing for some of the overall application to be up and running fairly quickly to compliment the unit testing.

  8. #8
    always learning . . .
    Join Date
    Nov 2003
    Location
    UK
    Posts
    821
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is some sound advice even if it is your opinion.

    Do you have any sample (small part of a project you did) where you can show me your blueprint? I'm interested in seeing an example. Totally respected if that can't be done.

    Tar for advice

  9. #9
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Explanation of my previous statements: I have no experience with VWD Express save installing it and helping some people do some static html stuff in it.

    As for the other very interesting debate here about how much pre-planning: I am definitely in the sketch school of thought. I tend to get a very good idea of where I am going, and only drill into details up front where necessary for things like public APIs. If I do alot of diagrams, they tend to be more workflows and things. I generally let the code deal with the code and schedule time for heavy refactoring at various stages.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •