how to Separating coding behind file from layout  document

Posted on 2011-10-14
Last Modified: 2013-12-16
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

Question by:Atouray
    LVL 19

    Accepted Solution

    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]"...


    Author Comment

    i don't see any check box after following  your steps.
    pls see the attached file evident-sup.docx
    LVL 19

    Assisted Solution

    by:Manoj Patil
    Have you tried the second step i.e for Existing File

    Add a class file
    LVL 19

    Expert Comment

    by:Manoj Patil
    Check the screen shot  Add New Item Window

    Author Closing Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Suggested Solutions

    Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now