Background: I'm trying to make an extremely light news sort of...thing that relies entirely on hard code ASPX documents (not my decision). What I would like to do is create a bit of dynamic updating by having the main news page pull the latest ASPX file from a folder and get its "TopContent" section on the main page. How would I best be able to do that? I'm stuck with ASP.NET 2.0 on this project as well.
So I didn't quite transclude ASPX documents, but I found a way to get this to work by having XML files with the data pieces I needed and just using that. No problem.
In detailed: An XML file containing the title, the top content and the main content and then using a URL argument to figure out which file to open.
So I imported this aspx page done by a former dev who worked for the company I'm in now. I found that the aspx page left by him doesn't have a codebehind file so I assumed this wasn't the source code. I can't find the source so I added a code file and try to work it out on my own. But my main concern is this: clients can't access the code behind, right? Is a manually added code file subject to the same protection?
The codebehind file is there as a place to put your server side code. However it's technically not necessary to have one since you can put the code in the aspx file using c# script tags. It's however recommended to put it in the codebehind file for better separation between markup and code.
It does not matter if you add it yourself or if Visual Studio adds it for you. It does not change anything in terms of access. In all events it executes on the server.
If your server is properly configured to run ASP.NET applications - which I believe it is - then IIS will not serve .cs files to a client. These will normally be accessible only through FTP. Try it yourself, by browsing to any .cs file in your application :)
Also notice that what you get when you browse to an .aspx file is not the very same code you'd see in Visual Studio, but the result of that being processed. IIS will serve the resulting HTML. So even if you have server side code in the ASPX file, that won't be visible to an end user browsing through your application.
Sounds like a web application project; in this case, the code is in the code-behind file as #TGH mentioned, and the code would be in the DLL compiled for the web application. Therefore, the only way to get that code is use a tool like Telerik JustDecompile, and decompile that DLL to grab the source code for EVERY file in the project. It would be much better to have the source, as these decompile tools do not include everything in that code-behind file.
I'm not new to programming but am new to Visual Studio, MVC, C#, ASP.NET, and EXT.NET, i.e. all of the tools I am trying to use.
I am trying to create an Ext.Net 2.0 MVC4 project and was given a similar (in functionality) non-MVC project for reference.
I see that this non-MVC project has .aspx and .aspx.cs files. It seems like the .aspx file basically maps to the "View" in MVC that I want to make... And the .aspx.cs file has the functions that relate to the .aspx file - so is that like the "Controller"? Though the .aspx file also has some functions that seem to not be entirely view-related...
Could someone give me a quick overview or a place to start with this?
ASPX files usually will have the UI and will which is usually HTML tags, some ASP.NET server control embed code (which ultimately produce some HTML markups). ASPX.CS file (usually called "code-behind") will have server-side coding in C#.
If needed, I would relate ASPX page to View and ASPX.CS to Controller action methods.
You have to remember that in webforms, there are ASP.NET controls we will be using in the ASPX file to render some HTML. Examples are TextBox, DataGrid, etc. In MVC, there is nothing called Server control. The View will be pure, handwritten HTML.
If needed, you can create a Hybrid project which is a combination of MVC and webforms. Scott has a post explaining about it here.
No ViewState in MVC :)
When switching from ASP.NET Webforms to MVC, One important thing you have to understand is that MVC architecture tries to stick with the truth that HTTP is stateless. There is no viewstate available in MVC. So you need to make sure that you are repopulating the data in every HTTP Request, as needed. Folks usually run into problems in loading DropDownlist in MVC. There are a lot of answers here in SO about how to handle dropdown lists on postback (when form is posted).
I suggest that you look into some beginner-level tutorials on ASP.NET MVC and start building your app step-by-step, and if you run into any issues, post a (new) question with relevant details.
Good luck, and welcome to the wonderful world of MVC. :)
It sounds like you haven't created an MVC project, but rather a WebForms project.
The *.aspx files are the markup and the *.aspx.cs files are the code-behind files. Code-behind files handle the .NET code for any server-side controls in the *.aspx files.
Checkout Wikipedia's document on ASP.NET, http://en.wikipedia.org/wiki/ASP.NET.
It states:
Web forms are contained in files with a ".aspx" extension; these files
typically contain static (X)HTML markup, as well as markup defining
server-side Web Controls and User Controls where the developers place
all the rc content for the Web page.
Additionally, dynamic code which runs on the server can be placed in a
page within a block <% -- dynamic code -- %>, which is similar to
other Web development technologies such as PHP, JSP, and ASP. With
ASP.NET Framework 2.0, Microsoft introduced a new code-behind model
which allows static text to remain on the .aspx page, while dynamic
code remains in an .aspx.vb or .aspx.cs or .aspx.fs file (depending on
the programming language used).
The .cs file names .aspx.cs is the code behind that goes with .aspx, which generally holds the html, css, javascript and other client side controls.
Generally, dynamic code (C# in this case because of the .cs on the file name) goes in the .cs file as a "good practice" to keep dynamic code and static html separated. Another reason for this abstraction is that the .aspx.cs code is run server side, while the .aspx file is compiled on the server and is then served to the web client requesting it.
Additionally, for MVC, I would suggest using a different view model, specifically Razor, which uses .cshtml files instead of the .aspx.cs and .aspx because they are easier to follow. The reason for the change in MVC is that MVC uses the MVC pattern to abstract layers of code so that .aspx and .aspxcs are not as needed. From a personal experience, I have used both Razor and Webforms (.aspx/.aspx.cs) view models with MVC and I find Razor to be much easier to code/maintain and use.
The aspx file contains your page markup. It's automatically converted into code by ASP.NET.
The cs file contains the code behind your page (initialization, event handlers, etc.). You have to write that code yourself.
These two files are related with the inheritance and he Inherits attribute of the #Page directive associates the page markup to the code behind
.aspx is your markup file. Contains things such as HTML, CSS, JavaScript, and ASP markup.
this .cs file is referred to as a codebehind file. This is where you do thing that may not be available or u are not comfortable doing in scripting languages. Generally aspx is run on the client side while the code behind is executed on the server.
I have a aspx page and I'd like to run it into a sharepoint folder. Is there a way to execute this page like a html page? What I really need is to run a c# code that is together the aspx page (code behind) to read a SQLite database and shows the result in a good interface (html-css-javascript).
Obs.: I have a assembly reference for the SQLite.
Thanks a lot!
You need to create an application page inside sharepoint and move your code in that application page. its very simple, please see this link.
http://www.c-sharpcorner.com/uploadfile/anavijai/how-to-create-custom-sharepoint-2010-application-page-using-visual-studio-2010/
Please note that application page only support web forms and not MVC
Not sure "run it into a sharepoint folder" means... You can't have page with code behind in regular SharePoint folders.
You can put ASPX pages (even with codebehind) in Layouts folder on server's disk and they will be avaiable with ....\layouts\your_page.aspx urls.
I want to make message strings independent of aspx file and code behind page
I want to know how to use the resource files with code behind to achieve this?
or is there any other way to do this, other than using resource files?
In software, there is always more then one way. ;)
But if you want to separate string literals from an aspx page, resource (resx) files are the accepted standard.
This article might help you get rolling.