Hello, I am quite new in ASP.NET, I am currently studying C# (still am at the beginning), and I got this task to separate the "code for the presentation part", so I would get two separate files - Test.aspx and Test.aspx.cs. i know that the .cs is actually the C# file, but I have no idea which how to do the separation. So can you please help me, guide me through or something, should I write a form or anything... Here is my (short and simple) code.

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Test.aspx.cs" Inherits="WebApplication1._Default" %>

<!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>The Test Web Server</title>
    <script language = "C#" runat ="server">
        void Page_Load(object sender, EventArgs e)
        {
            time.Text = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" +
                 DateTime.Now.Second.ToString();

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>Welcome</h1>
    Current time in Skopje:
    <asp:Label ID ="time" runat ="server" Text =""></asp:Label>
    </div>
    </form>
</body>
</html>

here is the webform1.aspx :

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication3.WebForm1" %>

<!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 id="Head1" runat="server">
    <title>The Test Web Server</title>
    
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <h1>Welcome</h1>
    Current time in Skopje:
    <asp:Label ID ="time" runat ="server" Text =""></asp:Label>
    </div>
    </form>
</body>
</html>

here is webform1.aspx.cs :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication3
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected Label time;
        protected void Page_Load(object sender, EventArgs e)
        {
            time.Text = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString() + ":" +
                 DateTime.Now.Second.ToString();
           
        }
    }
}

you dont have to worry about this seperation since visual studio does it for you automatically.

hi,

i aggree with the previous poster visual studion does it for you.when create a form in vs 2005 you will have two view design and code view.you can do your design part in design view and coding part in code view.

Thank you very much, I see the difference now, and yes - it had been automatically done. Greetings

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.