1

I've been wrestling with this all day. Opening up an old web application trying to add a method to my page (default.aspx) and have my code behind default.aspx.cs which is referenced in the page:

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HoursWorked._Default" %>
<%@ Import Namespace="HoursWorked" %>

Some of the symptoms I'm having are intellisense not "seeing" any of the controls from the page, when I double click the button control in the Designer, it creates the following:

<script runat="server">

protected void ButtonShowUnderEight_Click(object sender, EventArgs e)
{

}
</script>

Code behind starts off as (after all of my using statements):

namespace HoursWorked
{
    public partial class _Default : Page
    {

Any ideas?

Thanks, Tim

3
  • Please show us the code for the button. Commented Jan 5, 2015 at 20:38
  • <asp:Button ID="ButtonShowUnderEight" runat="server" Text="Show Under 8 Off" OnClick="ButtonShowUnderEight_Click" /> Commented Jan 5, 2015 at 20:52
  • This is all from code on my dev/test server. My local dev box, where I originally did development, I can open the project up and adding the event handler works properly. I can double click the button and the auto-wireup works and places it in the code-behind. Commented Jan 5, 2015 at 21:16

3 Answers 3

1

In my case (VS2013) what helped was based on this link:

  1. Remove CodeBehind="yourfile.aspx.cs" from the first line of your .aspx file which will cause the c# event handler code to be placed into your .aspx source file instead.

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HoursWorked._Default" %>
    

    So you are left with:

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" Inherits="HoursWorked._Default" %>
    
  2. Now double-click the control in the Designer which should now pop the event handler code inside script tags within your aspx.

  3. Next, restore the CodeBehind="yourfile.aspx.cs" you had removed in the first step.

    <%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HoursWorked._Default" %>
    
  4. Finally, double-click the control which now pops the event handler code inside yourfile.aspx.cs!

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

Comments

0

Replace

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="HoursWorked._Default" %>

with

<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="._Default" %>

It does not like when you inherit

Inherits="HoursWorked.Default"

P.S, you can also remove

<%@ Import Namespace="HoursWorked" %>

2 Comments

I've tried that. I get "Could not load type: '._Default'."
@CooperT I got the same error after messing around, apparently adding different projects to a solution does this. Try removing that project and readding it. Should be fixed then
0

I ended up going back to my original local solution instead of trying to use the ones on my dev and prod servers. No clue why they were having this issue compared to my original local solution.

Not going to help anyone else having this issue, but instead of investing more time trying to solve this... I'm sure if I compared everything in my solution folder, something might stick out.

Tim

Comments

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.