Microsoft.NET

……………………………………………….Expertise in .NET Technologies

Using inline code in ASP.NET (C# and VB.Net)

Posted by Ravi Varma Thumati on January 5, 2011

Using this syntax, you can use inline code in ASP.NET (.aspx) pages. The server-side code will be automatically compiled by the .NET framework the first time the page is requested on the server. The compiled .dll file is stored in the “Temporary ASP.NET Files” system folder. Changing the code in .aspx files will trigger a new compilation, generating new .dll files. The old .dll files are phased out by the framework and eventually deleted.

C#

<%@ Import Namespace=”System” %>
<%@ Page Language=”c#”%>

<script runat=”server”>
public string ServerSideFunction(string input)
{
return “Hello ” + input;
}
</script>

<% string pageVariable = “world”; %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml&#8221; xml:lang=”en” lang=”en”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″ />
<title>ASP.NET inline</title>
</head>
<body>
<% =ServerSideFunction(pageVariable) %>
</body>
</html>
VB.Net

<%@ Import Namespace=”System” %>
<%@ Page Language=”VB” %>

<script runat=”server”>
Public Function ServerSideFunction(input As String) As String
ServerSideFunction = “Hello ” & input
End Function
</script>

<% Dim pageVariable As String = “world” %>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”&gt;
<html xmlns=”http://www.w3.org/1999/xhtml&#8221; xml:lang=”en” lang=”en”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=windows-1252″ />
<title>ASP.NET inline</title>
</head>
<body>
<% =ServerSideFunction(pageVariable) %>
</body>
</html>

 

Advertisements

6 Responses to “Using inline code in ASP.NET (C# and VB.Net)”

  1. i likely it Using inline code in ASP.trap (C# and VB.Net) « Microsoft.NET now im your rss reader

  2. Hello. magnificent job. I did not imagine this. This is a great story. Thanks!

  3. i parallel it Using inline code in ASP.NET (C# and VB.Net) « Microsoft.without deductions things being at that time im your rss reader

  4. abelbrain said

    this is very useful c# code. thanks for sharing this code..

  5. Hey – good weblog, simply trying around some blogs, appears a reasonably good platform You Are using. I’m presently utilizing Drupal for a number of of my websites but trying to change one in all them over to a platform very much the identical to yours as a trial run. Anything particularly you’d advocate about it?

  6. free mp3 said

    i i equal it Using inline code in ASP.NET (C# and VB.get or gain over and above expenses) « Microsoft.NET at this moment im your rss reader

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: