|
 |
aspx_beginners thread: code behind
Message #1 by "Nick" <nick@g...> on Fri, 26 Jul 2002 11:04:42 +0700
|
|
dear all....
hai, i wanna know what is code behind, is there any articles or samples could help me ??
thanks
Message #2 by philip.hatt@a... on Fri, 26 Jul 2002 08:09:09
|
|
Hello.
Code behind is a method for separating .NET code from HTML code. In other
words: the user interface code is in one file and the functionality for
the webform is another file.
Exempel:
#User interface starts here#
<%@ Page inherits="SomeWebForm" src="SomeWebForm.vb"%>
<html>
<body>
<form runat="server">
<asp:button id="someButton" runat="server" />
</form>
</body>
</html>
#User interface stops here
##VB.NET Code
imports system
imports system.web.ui
public class SomeWebForm: inherits Page
'the functionality goes here
end class
##VB.NET code stops
There is a lot written about this topic on the web...
Best regards,
Philip
Message #3 by "Nick" <nick@g...> on Fri, 26 Jul 2002 15:23:18 +0700
|
|
thanks philip, so i little bit confuse, in ur code you write
src="SomeWebForm.vb" what it's mean and what the different between
Inherits="blank blank blank" ??
----- Original Message -----
From: <philip.hatt@a...>
To: "aspx_beginners" <aspx_beginners@p...>
Sent: Friday, July 26, 2002 8:09 AM
Subject: [aspx_beginners] Re: code behind
> Hello.
>
> Code behind is a method for separating .NET code from HTML code. In other
> words: the user interface code is in one file and the functionality for
> the webform is another file.
>
> Exempel:
> #User interface starts here#
>
> <%@ Page inherits="SomeWebForm" src="SomeWebForm.vb"%>
> <html>
> <body>
> <form runat="server">
> <asp:button id="someButton" runat="server" />
> </form>
> </body>
> </html>
>
> #User interface stops here
>
> ##VB.NET Code
>
> imports system
> imports system.web.ui
> public class SomeWebForm: inherits Page
> 'the functionality goes here
> end class
>
> ##VB.NET code stops
>
> There is a lot written about this topic on the web...
>
> Best regards,
>
> Philip
>
Message #4 by "Sri Vidya" <svsvidya@i...> on Fri, 26 Jul 2002 15:41:32 +0530
|
|
Hi Nick,
In an ASP page, you can write the business logic either within the
.aspx page or separate it and write into another document that can be
referenced from the .aspx page.
In the example provided by Phillip, the presentation page (see code
below) defines only the presentation layer. That is the objects
required to be displayed on the page. If you observe the first line of
the code (See the code for WebForm2.aspx) you will note that this file
is referencing another file called WebForm2.aspx.vb
Now, this SomeWebForm.VB contains the processing logic for the
Button_Click Event. All you need to do is compile this
WebForm2.aspx.vb into a WebForm2.dll using the VBC command. Then copy
this dll into the BIN directory of your web server or the virtual
directory. Execute the WebForm2.aspx page from the browser.
>> Example: (FileName = WebForm2.aspx)
<%@ Page Language="VB" AutoEventWireUp="False"
CodeBehind="WebForm2.aspx.vb" Inherits="WebForm2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> WebForm2.aspx </title>
</head>
<body>
<form id="Form1" method="Post" runat="server">
<asp:Button id="Button1" Text="Click Here" Runat="server" />
<asp:Label id="Label1" Runat="server"> Label </asp:Label>
</form>
</body>
</html>
>> ##VB.NET Code (FileName = WebForm2.aspx.vb)
Public Class WebForm2
Inherits System.Web.UI.Page
Protected WithEvents Button1 as System.Web.UI.WebControls.Button
Protected WithEvents Label1 as System.Web.UI.WebControls.Label
Private Sub Button1_Click(ByVal s as System.Object, ByVal e as
System.EventArgs) Handles Button1.Click
Label1.Text = " Button was clicked !" & system.DateTime.Now
End Sub
End Class
Hope this helps.
Cheers,
Vidya.
On Fri, 26 Jul 2002 15:23:18 +0700
"Nick" <nick@g...> wrote:
>thanks philip, so i little bit confuse, in ur code you write
>src="SomeWebForm.vb" what it's mean and what the different between
>Inherits="blank blank blank" ??
>
>----- Original Message -----
>From: <philip.hatt@a...>
>To: "aspx_beginners" <aspx_beginners@p...>
>Sent: Friday, July 26, 2002 8:09 AM
>Subject: [aspx_beginners] Re: code behind
>
>
>> Hello.
>>
>> Code behind is a method for separating .NET code from HTML code. In
>>other
>> words: the user interface code is in one file and the functionality
>>for
>> the webform is another file.
>>
>> Exempel:
>> #User interface starts here#
>>
>> <%@ Page inherits="SomeWebForm" src="SomeWebForm.vb"%>
>> <html>
>> <body>
>> <form runat="server">
>> <asp:button id="someButton" runat="server" />
>> </form>
>> </body>
>> </html>
>>
>> #User interface stops here
>>
>> ##VB.NET Code
>>
>> imports system
>> imports system.web.ui
>> public class SomeWebForm: inherits Page
>> 'the functionality goes here
>> end class
>>
>> ##VB.NET code stops
>>
>> There is a lot written about this topic on the web...
>>
>> Best regards,
>>
>> Philip
>>
>
>
---------------------------------------------
http://mail.indiainfo.com
India's first ISO certified portal
Check world time at http://time.indiainfo.com
|
|
 |