user384080
user384080

Reputation: 4692

How to add code behind manually on asp.net

I have a website on the IIS but it has only the aspx file. Now I need to add the code behind for some pages. How do I go about this?

I've been trying to add the attribute "codebehind" and "autoeventwireup" on the top of the aspx file but no luck (the page_load event is not being called). Also, if I double click on the button from the design view in Visual Studio, it creates the javascript handle (not the server code).

Upvotes: 0

Views: 1343

Answers (2)

dave
dave

Reputation: 1364

In your page directive on the aspx page (<%@ Page...), you need two pieces:

1) CodeFile="Default.aspx.vb" 
2) Inherits="_Default"

In your code-behind file, you need two things:

1) The file name has to be whatever you specified above (CodeFile = "...)
2) the class name has to be whatever you specified above (Inherits="_...)

For example, if your aspx page was named "default.aspx" then your page direction in the aspx page would look similar to this:

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

And your code-behind would look similar to this:

Partial Class _Default
    Inherits System.Web.UI.Page

End Class

Upvotes: 1

Muad&#39;Dib
Muad&#39;Dib

Reputation: 29276

you want the @page directive and the class attribute. MSDN docs here

Upvotes: 0

Related Questions