Non-code behind to code behind

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
 
M

Masudur

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
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top