Non-code behind to code behind

  • Thread starter Thread starter John
  • Start date Start date
J

John

Hi

I have a non code behind web form done previously. How can I turn it into a
web form with an associated code behind file?

Thanks

Regards
 
Hi

I have a non code behind web form done previously. How can I turn it into a
web form with an associated code behind file?

Thanks

Regards

Hi...
Lets say you have a page... name Test.aspx
.... add a class
Test.aspx.cs
by default the class is

public class Test
{
public Test()
{
//
// TODO: Add constructor logic here
//
}
}

modify the class
public partial class Test:Page
{
public Test()
{
//
// TODO: Add constructor logic here
//
}
}

making it partial and inherit from "page"

now make change the aspx file...

it should be like this
<%@ Page Language="C#" %>

modify it to

<%@ Page Language="C#" Inherits="Test" CodeFile="~/Test.aspx.cs"
AutoEventWireup="true" %>

thats it... you are good to go

Thanks

Masudur
www.kaz.com.bd
 
Simple way:
1) add a brand new WebForm.aspx page to your solution.
2) Copy all your markup from the original to the new
3) copy all the code between the <script runat=server>... tags into the
codebehind.
4) try it and fix any errors.
 
Back
Top