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 allowes developer to write C# sysntax inside the <% %> block. Its mease it can contain C# block of code same as written in .cs file.
This simple program declare a string and print it using c# sysntax. 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.
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" >
Source code of How to Declare variable in ASP.NET Page using C#
<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