• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

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 asp.net.
i have radiobuttons and grid view on my layout document.
please help.
layout:
<%@ 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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

        </script>   
</head>
<body>
    <form id="form1" runat="server">
    <div>
    
              <table>
                    <tr><td valign= "top"><img src = "statistics.gif"  style= "width:200px; height:100px"/></td></tr>
                            
               </table>        
            
             <center> <p> my title :</p></center>
            
         </div>   
         <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 />
     <h1>

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


</h1>
            </div> 
    
    </form>
</body>
</html>

Open in new window

0
Atouray
Asked:
Atouray
  • 3
  • 2
2 Solutions
 
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:
Code:
...CodeFile="[Your file name].aspx.cs" Inherits="[Your class name]"...




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

Add a class file
0
 
Manoj PatilSr. Software EngineerCommented:
Check the screen shot  Add New Item Window
0
 
AtourayAuthor Commented:
thanks
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now