I am using VS2010 and I created a ASP.net empty web application, but I cannot for the life of me get it to generate an index.aspx.cs file. I double click any control in the view and I just get nothing. What could I possibly be missing? I used to be able to just double click on a control and it would automatically generate the .cs if it didn't exist.
2 Answers
When you add a new item to the project and pick "web form" as type, you should have both index.aspx and the code behind file. Double-clicking controls does not generate the code behind file, it only adds event handlers to it. Take a look at this walkthrough.
2 Comments
Emerica.
That would explain it. I was importing aspx files from another project and they weren't dropping in with .cs files. It is however possible to create them manually right?
Diego
Of course, just create an empty file with the correct name (same as the
.aspx, but with .cs) and make sure it matches the CodeBehind attribute of the @Page tag in the aspx (switch to markup view and scroll all the way to the top to see it). Also, the class name in the .cs file should match whatever the Inherits attribute of the @Page tag says.In your project file (csproj), make sure that you have the DependentUpon tag which indicates that the aspx.cs file depends on the aspx file. Here is an example:
<Compile Include="dir\myFile.aspx.cs">
<DependentUpon>myFile.aspx</DependentUpon>
<SubType>ASPXCodeBehind</SubType>
</Compile>
This worked for me.
1 Comment
Sharon Watinsan
Which means i have to create a myFile.aspx.cs inside the view ? And where should i have the above code ?