ASP.NET / C#

How to write a basic function

Functions are similar to subroutes with the difference being that functions return a value. Functions can be used when you want to run the same code against several pieces of data. Instead of writing the code out for each piece of data, write it once, put it in a function then call the function from within the body of the page. Place your function in either a script tag in the header or in your code-behind file.

VB.NET

Function getCompanyName() as String
    Return "Multimedia Designs"
End Function

Sub Page_Load(s as object, e as eventargs)
   lblmsg.text = getCompanyName()
end Sub

On the asp.net page:

<asp:label id="lblmsg" runat="server" />

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