简体   繁体   中英

Creating Code-Behind file - aspx.cs

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM