Thursday, March 22, 2012

Newbie Microsoft VS.net Code Behind Problem

Hi!!
I am using ASP.net with Code Behind for the first time on Visual Studio. I had some problems and questions.
When we create a Web App Project in VS do i need to copy the resx file too?
Actually i made a page. It is now a .aspx file, a .aspx.vb and a .aspx.resx file. I also made a new class in a VB file. when i built the project i found the dll in the bin folder.
I uploaded the stuff onto the web page (all three, global.asax, web.config) and the dll into the bin folder of my websites root, but it doesnt work. I made some changes in my project and rebuilt it, but the changes werent reflected (i added a Response.Write in the Page_Load).
I copied the vb file to the sites root too but the thing doesnt work. Its working perfectly on my localhost.
I also wanted to know that i added the class in the file by choosing Add Class in the projects menu. So its automatically compiled to a dll right? Another thing is that in localhost the site was working in a folder and not directly in wwwroot (in a folder called even). So when i was to import my custom made namespace it was referenced as Even.MyNameSpace, but normally i compile it to a dll and do it directly.
Another thing is that i tried compiling it to a dll. Visual Studio tools and then VS.net Command prompt, followed by vbc /t:library myVbFile.vb but it couldnt compile. It couldnt find the namespace i imported. It cant even import namespaces like System.Xml etc.
Someone please help. Please tell me if i am not clear as this is a very basic problem.Lots of problems and possible issues here. To start with, you'd have to explain what "didn't work" means. Have you tested a very simple Hello World! ASPX file, with no code behind, to make sure you understand the basics of working with VS and your web host?
Jeff
Well I uploaded a file which on clicking over a button shows the contents of an XML file.
I made a namespace and added a class in it to access and XML file. In my pages code behind i use this class to return the data. (the xml contains values coupled together). The class has many function like getData1, getData2 etc.
The Class for reading the XML throws a user created exception (that i made) if no data existed, else it threw the usual exception. This is caught by the page in which i have called the xml reader class. If its the user exception it simply writes that no data was found else it writes the exceptions text. So initially as i said when i uploaded it gave a message written "The remote server returned an error: (404) Not Found." as the exception's message. I then uploaded all the files i mentioned alongwith the assemblyinfo. But it still didnt work. Then i uploaded a new file which had a "page loaded" string in its page_load, but the changes were not affected. I rebuilt the project in VS and then uploaded the new resx, aspx.vb and aspx files, but to no avail.
I have worked on Dreamweaver and without code behind. Later i tried to compile the VB file but the VS .net command prompt compiler gave me that error. My VS by default creates page with code behind only. Can this be changed? Actually i want to create my own class and compile it to a dll and then make the page inherit from the class from the dll.
I have another question. I had named my project even in VS and then started working in the folder even in the wwwroot. Now i uploaded the whole folder onto the site in a folder placed in the root with the same name as even. Made it an IIS application but still the code doesnt run. It started workng after i uploaded the aspnet_client to the even folder.
Can anyone tell me how i can deploy this to my root? Moreover when i change any file what all files do i need to upload again? Is there a way to prevent VS to automatically creating a page behind as i would like to put all my classes into a dll and then use them as page behind. Moreover when i build the project are the .vb files automatically compiled to dll?
I have one basic question. How do we deploy our VS projects to our web site? I am not able to get any file to work on the website. I have no problems at my own computer and everything is working fine. I am sure a lot of people here can teach me how to deploy VS projects? What all changes etc have to be done?
Im no expert here but if you compile this as a release instead of a Debug build and then create a "Web Setup Project" under the New Projects and then choose Setup and Deployment Projects. Then you can "install" the website to your webserver.
Cleako
I just noticed another thing in your post. If you are going to want your classes in a DLLs separate from the main project then you need to create a class library and place all of your classes that you would like to keep separate in there and then just create instances of those classes within the library in the other project.
Cleako
As you suggested i created a class library. Then i made a file in some Namespace and put in a class. After building it i copied the dll from the bin folder to my sites bin folder. But still i couldnt use the class in my aspx pages. If i compile the same class through command line
vbc /t:library /out:MyClass.dll SomeClass.vb
then it works.
Moreover one of my classes had Imports System.Xml in it. when i build it, it works but when i use the above command line statement in the VS.net Command prompt i get an error saying the file couldnt be found. I dont know what to do and am stuck.
I tried adding the class library to my project, but still cant use it. How do other people generally implement code behind without using VS? I want to create classes in VS but use them in my aspx pages which i make in Dreamweaver.

0 comments:

Post a Comment