Home > Microsoft .Net Development Tips > ASP.NET Development > Code behind page sample
Win Development Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

ASP.NET DEVELOPMENT

Code behind page sample


Kunal Cheda
06.10.2003
Rating: -2.67- (out of 5)


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


Please let other users know how useful this tip is by rating it below. Do you have a tip or code of your own you'd like to share? Submit it here.


Code behind is a new feature of ASP.NET that lets you separate code and presentation in different files. With this kind of technique you could write a presentation in an .aspx file and the code could be any .NET-compatible language (C#, VB.NET, etc.). The benefit is that it becomes easy to manage code and the presentation of it, while the work can be distributed -- people good at presentation can work on that part of the application and the programmer could work just on the coding part.

There are actually two physical files on the disk where a tag in .aspx files tells the name of the class and the name of the physical file. Note: Inherit tells the name of the class in the code behind file and SCR is source file. When the default.aspx loads, you see that page_load event is called in the default.vb file, and, similarly, on click the button we see the code gets called from the default.vb file.

Default.aspx

<%@Page language="vb" inherits="CodeBehindClass"
src="Default.vb" %>
<form runat="server">
<asp:button id="button1" text="button 1" onclick="button1_click"
runat="server" />
<asp:label id="lbl" text="label and button in the aspx file " 
runat="server" />
</form>

Default.vb

imports system
imports system.web
imports system.web.ui
imports system.web.ui.webcontrols
imports system.web.ui.htmlcontrols
      public class CodeBehindClass 
      Inherits System.web.ui.page
             public lbl as label
             sub Page_Load(sender as object,e as eventargs)
                        lbl.Text = "page load in Code Behind" 
             end sub
             sub Button1_click(sender as object,e as eventargs)
                     lbl.text = "Button click in Code Behind"
              end sub
       end class

Save both the pages to wwwroot and run in Default.aspx in the browser.

Rate this Tip
To rate tips, you must be a member of SearchWinDevelopment.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
ASP.NET Development
How to use jQuery to solve Javascript browser compatibility problems
How to write an out-of-browser Silverlight 3 application in 3 steps
Silverlight 3 beta SDK download lets developers try new RIA features
Visual Studio's IntelliSense for jQuery doesn't autocomplete correctly
Dundas Map for .NET kicks up geographic visualization
Return to CodePlex: Into the Sandcastle…
VBScript Tutorial
Use PHP with Visual Studio to create Web sites
Visual Studio Team System Add-ins: Conchango Scrum for Team System and Scrum Dashboard
Visual Studio 2008 and .NET Framework 3.5 SP1 introduces ADO .NET Entity Designer

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Database Programming Solutions - .NET XML, Visual Studio LINQ, ORM .NET
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2000 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts