Server side coding (C#, VB or any other language can be used with ASP.NET page. Here is sample code to implement the same. ASP.NET page allows developer to write C# syntax inside the <% %> block. Its means it can contain C# block of code same as written in .cs file.
This simple program declare a string and print it using c# syntax. The whole code for aspx page is given below. Please note that This page does not contain the .cs file.
you need to add AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" in Page directive to work with .cs file.
Source Code:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<body>
<%
string strStatement;
strStatement = "This is an example of C# coding within ASP.NET Page.";
Response.Write("My Statement is: " + strStatement);
%>
</body>
</html>
No comments:
Post a Comment