1

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.

1
  • Is it possible you accidentally created an empty ASP.NET MVC project? Commented Mar 1, 2012 at 3:32

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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.
1

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

Which means i have to create a myFile.aspx.cs inside the view ? And where should i have the above code ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.