I am currently using Visual Studio 2012 to design aspx pages and have a page which uses a MasterPage which I will call it "a.aspx" for simplicity's sake, and unlike my other pages, "a.aspx" does not have a .cs file attached to it which I assume is because it had a Master Page. Whenever I drag items like buttons into the contentholder of "a.aspx", the code behind page brings me to the aspx page and not the cs page. And I can't import assembly references which I need to because I require some SQL connection in "a.aspx"
So how can I create a webform with a master page while being able to have the contents within my contenthandler to be mqanipulated through a .cs file or can I perform functions in the aspx page too?
You can have all your functions in same aspx file, or you can divide it into two files: aspx and cs. Just enable "place code in separate file" checkbox in "add new item" dialog.
This place code in separate file option depends on the type of project you are building:
1) If you are building a Web Application then (File | New > Project, doesn't have an /App_Code folder, compiles all .cs/.vb files into one .dll in the /bin folder) then you don't have the option to not create a separate code file, and when you add a new item it's either a Web Form or a Web Form using Master Page.
2) If you are building a Web Site (File | New > Web Site, contains an /App_Code folder, the code is not compiled into a .dll in the /bin folder) then you will have the option (ticked by default in VS2008/2010/2012) to Place code in separate file, and also Select master page.
Related
I'm using App_LocalResources on my project without problems, that was until i created a aspx page inside a folder, I created the resx file with the same name as i did for others but when the page is inside a folder I cant call the resources for that page.
The way I call resources is:
bt_name.Text = GetLocalResourceObject("bt_name").ToString();
And the soluction struture for the aspx and resx are:
Solution -> Folder -> Page.aspx
Solution -> App_LocalResources -> Page.aspx.resx
What am I doing wrong?
If we create an ASP.NET Web Application in Visual Studio we can see that each and every .aspx file will have an associated auto generated .aspx.designer.cs file. But in case of an ASP.NET WebSite each aspx file has only a codebehind .aspx.cs file only.
My question is why ASP.NET Website does not have an auto generated designer .cs file?
What is the purpose of the auto generated designer file in case of the Web Application project? (I believe no one is touching that designer file)
why ASP.NET Website does not have an auto generated designer .cs file?
Because the code is compiled by the VisualStudio on the fly. Each page is compiled into a separate dll.
What is the purpose of the auto generated designer file in case of the Web Application project?
The designer file is created as a partial class which works as a bridge between aspx and aspx.cs file, which also provides IntelliSense support. No one touches the designer file because visual studio updated it automatically when any changes are made to the aspx file.
Below are references which will provide you more information:
ASP.NET Web Site or ASP.NET Web Application?
aspx.designer.cs how does it work?
Assume there is a asp.net 4.0 web application and it has a default.aspx and default.aspx.cs files in it. After I build the project, a dll that is named of the project created in the bin folder. So what the dll contains ? All code behind files compiled versions ?
If the aspx files still refers its CodeBehind file like below, then does the dll used for this aspx file or still code behind is valid to run the project ?
<%# Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="WebApplication3._Default" %>
In a Web Application, all your C# code is contained within the DLLs in the bin directory. There are a couple of exceptions, such as DLLs that you rely on that live in the GAC, for example. Using a web application ( your question says this is what you are using ), you do not need to deploy your *.cs code behind files.
A Web Site is different. Changes are detected and recompiled on the fly. You'll need to include your C# files code-behind files when creating a Web Site type project.
ASP.NET Web Site or ASP.NET Web Application?
A DLL is a library that contains code and data that can be used by more than one program at the same time:
What is a DLL?
Code-behind refers to code for your ASP.NET page that is contained within a separate class file. This allows a clean separation of your HTML from your presentation logic:
ASP.NET Code-Behind Model Overview
The code gets compiled into the assembly produced by your web project. You can change its name and default namespace as part of project options.
As I understood it, the ASPX file is only used IF the project is marked as being updatable, otherwise it is just a placeholder file.
I've been working in a multilanguage site build with asp.net and visual c#.
I'm using Local_resources to get my aspx files in Spanish and english.
If a use my aspx in the root of the website the Local_resources folder find the aproppiate resx for my aspx (because both have the same name). But if i put all my aspx into a folder created in the root directory, everything stop working:
as you can see i have a folder named "Inventario" and inside that folder i have Productos.aspx.
In App_LocalResources i have two files, one for spanish and one for english.
If i put Productos.aspx in the root directory they work fine, but i need them like in the image and like that is not working.
What should i do to the resx files to point to Inventario/Productos.aspx ?
Thank you very much.
You have to create a new App_LocalResources folder under Inventario, then copy Productos.aspx.*.resx from <root>\App_LocalResources to Inventario\App_LocalResources, then rebuild your solution.
I am developing a C# VS 2008 website, trying to add a Master file. I created a virtual directory in IIS housing the "Master" folder, containing the Master files.
Now how do I reference these files from my website in VS? One problem is I do not know where I need to publish this Master folder to. Other problem is I do not know how to reference this Master file in my aspx Page directive.
FYI, this master folder is physically located outside of c:\inetpub\ in a totally separate file location. Is this a problem?
I don't think you'll get away with using a virtual folder for that because any pages that refer to the master page will be in the same application space as the master page (remember that master pages are just user controls). You create child pages by using Visual Studio or Expression Web to select "create from master page"