how to open an aspx.cs file? - asp.net

i have some files with extension aspx.cs.
i tried opening them with visual studio c# 2008.
but all that opens is the code page, and not any design page.
what should i do?
i have to work on that project.
how to open those files, in which program/software?
please help.

Open the project .csproj or .sln file if there is one

The design files end with an extension aspx. The aspx.cs files are the code behind files and do not contain any design elements. Open the .aspx files in visual studio and you will have the proper design page.

The aspx.cs files only contain the code living behind the aspx files (that's why they are called code-behind files). If you want to be able to see the design you have to open an aspx file with the same name.
For example, if you have customers.aspx.cs, it contains the code-behind of a page called customers.aspx.
If you only have aspx.cs but not aspx, then you have a problem, as probably you lost files of the project.

Hai!!
.cs files are code files .aspx files are desidn files where you can switch from asp tages to asp design view but .cs files are c# code file that has no design
Happy Codding
Jay

For the Design File in .net Extension is only .aspx, Please open .aspx files instead of .aspx.cs Files

Related

the designer give to me .aspx file Website without .asp.cs

the designer give to me .aspx file Website without .asp.cs now i can't make any change because i don't have .CS file from .ASP can any one help me for getting .CS file by the way i already open the file by visual studio but just .aspx without seeing the design code
If you right-click on the .aspx file is there a context menu item named "Convert to Web Application"? If so click on it and VS should generate the designer cs file for you provided the .aspx file doesn't have errors.

Aspx control are not visible in cs file

I upload 2 page and downloaded same page.I added 2 more control in that file.But my aspx page control are not visible in my .cs file.When I am compling it,error occur on cs file(ddlbrand is not exist in current context).I am using vs 2005.I don't have designer file.(Only aspx and cs file).
Check if your controls are well formed, if the problem exists than I think you can't do that without the whole project and the solution file. You need to make changes in the project with visual studio. All the controls you add in the page are also added to the designer file.
Web Application Projects compile the .CS files as part of the build, and compile the ASPX's on the fly referencing your pre-built codebehind DLL - that's why you have to recompile if you change the code behind.
No designer file means you are working in ASP.Net Website project.
Check your aspx markup it must be missing some closing tag or some important parameter like runat="server"

How can include a reference in a standalone ascx control?

I have an ASP.NET ascx control. In the code behind file I need to add some reference (Sharepoint Libraries) to do some queries. How can I do that? Is a standalone control, I mean I have only the .ascx and the ascx.cs files. They are not part of any project so I don't have the tipical Property folder in the solution explorer, and they are loaded in a sharepoint page using the SmartPart control. So I'm little lost here, any help will be appreciated.
The simple answer is that you can't, In ASP.NET references are added to the web.config file of the application not the individual control. You would have to edit the SharePoint web.config file.
I found that if I put the dlls in a \bin folder at the same level of the control, I can use the code defined in it without problem. So I don't need to add a reference, by convention all dlls in that folder are available to my control. More clearly the file structure is like this:
\UserControls\bin\AnyCompiledLibrary.dll
\UserControls\AnyControl.ascx

How asp.net application works?

I am quite new to .NET development and I am just wondering how does it work?
My undermentioned points are:
While developing ASP.NET application, under the project we have files like:
pagename.aspx
pagename.aspx.cs
pagename.asp.desiger.cs
After adding certain functionality to pagename.aspx page, assuming I have the development required web application (this is not my concern, what is developed)
Now I'm going to deploy this application, I use web deployment MSI which creates the required files in the one folder called folderdelopyed.
This folder contains the files required to support this application but interesting does not contain pagename.aspx.cs and pagename.aspx.designer.cs files.
My question is if folderdelopyed does not contain .cs file, then how does it work to run the segment of code which I have written in this file called PageName.aspx.cs?
The code in your cs files gets compiled into a dll.
For Web Application projects this is one dll
For Web Site projects, this is a dll per page.
All of the code is now in the dll's in the bin folder of the website.
You can use a tool like ILSpy (http://wiki.sharpdevelop.net/ILSpy.ashx) to look inside the dll's and see your code.
In the old days, for classic ASP, the script used to be embedded in your page - a mix of code and HTML, and was interpreted at runtime.
I like the new way more :-)
ASP.NET code is compiled into Dynamic-link library files, also known as DLL files.
The code you write in your code behind, which is the files with .cs extension, is compiled and put into whole new file, with .dll extension - and that file is copied to the server, to the BIN folder of your site.
Depending on what project type you choose, it's possible to have several DLL files for the web application, changing in every build - see dash's answer for more details.
On every .aspx page you have referece to what DLL file to use, as the very first line. For example:
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="pagename.aspx.cs" Inherits="MyNameSpace.pagename" %>
In this example, the Inherits part determines what DLL to use. How? By the namespace, which is also the name of the DLL file.
When the above .aspx is requested by a browser, the .NET engine will go to the BIN folder, look for MyNameSpace.dll and in there look for class called pagename that inherits from the base Page class - all the rest is typical life cycle of ASP.NET page.
let me to say you something more Amazing.
you can hide your aspx file too.and put their content in to dll as same as your cs file put in dll.
you can make k aspx that just contain an address to the ddl file and no html body :D
that was greate!!! not only you can hide your cs file, you can hide you aspx file too :D

Where can I put my source files?

I am developing a web form using Visual Web Developer
Currently I have class source files in the same directory as the web form, or in the App_Code folder. I'd like to organise the files into folders within the web form folder, but I can't find a way of adding a reference to the folders, and they don't seem to be being picked up automatically.
These are files that are under constant development.
What is the asp.net/c#'s equivalent concept to c++'s #include?
This is a Web Site rather than a Web Application
I'd suggest taking these out into a separate class library project and you can then reference this DLL in your web project. You would then add a 'using' statement at the top of your web form code to include this reference.
In a C# file (foo.cs), you would use:
using MyProjectsDefaultNamespace.Folder1.Folder2
In an aspx or ascx file, you would use:
<%# Import Namespace="MyProjectsDefaultNamespace.Folder1.Folder2" %>
Never really thought of doing this, but i guess i would do this as follows.
A folder represents a namespace. So where it says inherits="Project.PageName" in your PageName.aspx file, it should state inherits="Project.Folder.Folder.PageName". You also have to change the namespace in your PageName.aspx.designer.cs and PageName.aspx.cs files.
EDIT:
For ASP.Net website simply adjust your CodeFile attribute:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Folder/Folder/Default.aspx.cs" Inherits="_Default" %>
Its not clear if you mean the codebehind .aspx.cs file or a standalone .cs class file.
You can't have .cs files loose in your main folder. It has to be in the app_code folder (or in a class library if you were doing a WAP).
Your .aspx.cs files are paired up with your .aspx file. I wouldn't recommend trying to move these files away if thats what you are trying to do.
The top level namespace that contains _Default or any code that doesnt appear to have a namespace is ASP. This is generally hidden within Visual Studio. So its true name is ASP._Default
And the answer is, obtained from looking into the other answers thanks:
Organise the files into folders within the App_Code folder, they will automatically be included.
Right click on project in solution explore
Go to Add> Add ASP.NET Folder > App_Code
Then add your files/folder structure there
BUT, be warned of what you put in there. Please refer to:
http://vishaljoshi.blogspot.com/2009/07/appcode-folder-doesnt-work-with-web.html
In the properties of the source file(s), you might want to set the "Build Action" property to "Compile"

Resources