how to Separating coding behind file from layout document

I created a web form , i want to separate the code from the layout.
 how can i achieve this in
i have radiobuttons and grid view on my layout document.
please help.
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Rejecteds.aspx.cs" Inherits="Changed.Rejecteds" Src = "Rejecteds.cs" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <title>Overview of Rejected abc</title>
      <script type = "text/css">
          p {border-style:double; border-width:thick;border-color: ActiveBorder;}
          p {text-align:center; font-size:24pt;color:white;background-color:Maroon;
            width: 1020px;
            margin-left: 4px;}

    <form id="form1" runat="server">
                    <tr><td valign= "top"><img src = "statistics.gif"  style= "width:200px; height:100px"/></td></tr>
             <center> <p> my title :</p></center>
         <div style="width: 775px">  
       <br />
      <asp:RadioButton ID="RadioButton1" runat="server" GroupName = "StationID" Text= "BK01" Checked ="true"  ForeColor= "black"/>  
      <br />  
      <asp:RadioButton ID="RadioButton2" runat="server" GroupName = "StaionID" Text = "BJL01" ForeColor = "black"/>  
      <br />
      <asp:RadioButton ID="RadioButton3" runat="server" GroupName = "StationID" Text = "BS01" ForeColor = "black"/>
      <br />
      <asp:RadioButton ID="RadioButton4" runat="server" GroupName = "StationID" Text = "FF01" ForeColor = "black"/>
      <br />
      <asp:RadioButton ID="RadioButton5" runat="server" GroupName = "StationID" Text = "SK01" ForeColor = "black"/>
      <br />

                <asp:GridView ID="GridView1" runat="server" Width="774px">


Open in new window

Who is Participating?
Manoj PatilSr. Software EngineerCommented:
To separate the code behind from Front Page, you can do it by following way

While adding new Item -  Right click on Web Site (or Project) in Solution Explorer then Add New Item. When you select Web Form, there is an CheckBox at the right bottom of the window "Place code in separate file" check it.  

For Existing File -
Create a separate CS file for ASPX page you have, and give same name as the associated ASPX file + ".CS". For example, if you have file "MyFile.aspx", you will create file "MyFile.aspx.cs".
Once you have your CS file(s), create your class(es) inside and transfer all the server-side code from your ASPX page(s)
Back in your ASPX page(s), where you have <%@ Page....%>, add the following attributes:
...CodeFile="[Your file name].aspx.cs" Inherits="[Your class name]"...

AtourayAuthor Commented:
i don't see any check box after following  your steps.
pls see the attached file evident-sup.docx
Manoj PatilSr. Software EngineerCommented:
Have you tried the second step i.e for Existing File

Add a class file
Manoj PatilSr. Software EngineerCommented:
Check the screen shot  Add New Item Window
AtourayAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.