Reputation: 1660
I got a file, let's call it MyPage.aspx. It has no codebehind and I need to add a codebehind file to it. Here's what I've done:
Still, it doesn't work. I cannot access runat=server elements from the codebehind. Strangely, I also noticed one more thing:
The definition of the class in MyPage.aspx.cs is as follows:
public partial class MyPage : System.Web.UI.Page
Normally, both words MyPage and Page in this line would be green. However, only the word MyPage is green and the word Page is still black.
I'm kinda stuck with this, any help would be appreciated.
Upvotes: 1
Views: 2431
Reputation: 401
in your aspx page you need to regrence the code behind page
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="MyPage.aspx.cs" Inherits="MyPage" %>
after you do that, you make a new class and name it MyPage.aspx.cs, just make sure that its in the same directory as your aspx page.
also give the class name inside the code behind _MyPAge
it should look like this after you reference your components
public partial class _MyPage : System.Web.UI.Page
Hope this helps.
Upvotes: 1