Florence Blogspot about asp.net tutorials and web design and web development

Sunday, July 27, 2008

Adding google MAP into your .NET website in just 15 minutes


Adding GOOGLE MAP into your .NET website in just 15 minutes by Florence

Ever wanted to add a Google Map to your site but only had 15 minutes to spare? Now you can add a map and still have time to brag to your mates and bask in the worship that (inevitably) comes afterward. Basically, the guys over at subgurim.net have already done all the hard work in writing the .Net wrapper for Google Maps. Problem is, the examples on their site are mostly in spanish & its a bit difficult to find out exactly what is needed to get everything working. But all this is cutting into your bragging time - so lets get started!

1. Get a Google Maps API key from here:http://www.google.com/apis/maps/

2. Download the SubGurim wrapper dll from here:http://en.googlemaps.subgurim.net/descargar.aspx

3. Unzip it, and put it in your \bin directory

4. Add it to your toolbox byTools -> Choose Toolbox Items -> Browse -> Select the .dll file -> OKGMap will now be in the ‘Standard’ area of your Toolbox.

5. Add a new webpage. 6. Drag the GMap from the toolbox onto the page. A new instance of the GMap will appear on the page, with the name ‘GMap1′

7. Add the following lines to your web.config file: appsettings add value="YourGoogleMapsAPIKeyHere" key="googlemaps.subgurim.net" appsettings 8. Add the following code to your Page.Load sub
Dim sStreetAddress As String Dim sMapKey As String = ConfigurationManager.AppSettings("googlemaps.subgurim.net") Dim GeoCode As Subgurim.Controles.GeoCode sStreetAddress = "100 Russell St. Melbourne. VIC. 3000. Australia" GeoCode = GMap1.geoCodeRequest(sStreetAddress, sMapKey) Dim gLatLng As New Subgurim.Controles.GLatLng(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng) GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal) Dim oMarker As New Subgurim.Controles.GMarker(gLatLng) GMap1.addGMarker(oMarker)
Press F5, and start basking in the glory!

Friday, July 11, 2008

Florence Blogspot about asp.net tutorials and web design and web development

Florence Blogspot about asp.net tutorials and web design and web development

VB.NET and C# Programming Basics

VB.NET and C# are great programming languages because they offer a structured way of programming. By structured, I mean that code is separated into modules,
where each module defines classes that can be imported and used in other modules. Both languages are relatively simple to get started with, yet offer features sophisticated enough for complex, large-scale enterprise applications.

Each language's ability to support more complex applications (its scalability) stems from the fact that it is an object-oriented programming (OOP) language. But ask seasoned developers what OOP really is, and they'll start throwing out buzzwords and catchphrases that are sure to confuse you - terms like polymorphism, inheritance, and encapsulation. In this article I'm going to explain the fundamentals of OOP and how good OOP style can help you develop better, more versatile Web applications down the road. This article will provide a basic OOP foundation that targets Web developers. In particular, we'll cover the following concepts:
Objects
Properties
Methods
Classes
Scope
Events
Inheritance

Objects
In OOP, one thinks of programming problems in terms of objects, properties, and methods. The best way to get a handle on these terms is to consider a real-world object and show how it might be represented in an OOP program. Many books use the example of a car to introduce OOP. I'll try to avoid that analogy and use something friendlier: my dog, an Australian Shepherd named Rayne.

Rayne is your average great, big, friendly, loving, playful mutt. You might describe him in terms of his physical properties: he's gray, white, brown, and black, stands roughly one and a half feet high, and is about three feet long. You might also describe some methods to make him do things: he sits when he hears the command "Sit," lies down when he hears the command "Lie down," and comes when his name is called.

So, if we were to represent Rayne in an OOP program, we'd probably start by creating a class called Dog. A class describes how certain types of objects look from a programming point of view. When we define a class, we must define the following two things:
Properties. Properties hold specific information relevant to that class of object. You can think of properties as characteristics of the objects that they represent. Our Dog class might have properties such as Color, Height, and Length.
Methods. Methods are actions that objects of the class can be told to perform. Methods are subroutines (if they don't return a value) or functions (if they do) that are specific to a given class. So the Dog class could have methods such as sit and lie_down.

Once we've defined a class, we can write code that creates objects of that class, using the class a little like a template. This means that objects of a particular class expose (or make available) the methods and properties defined by that class. So, we might create an instance of our Dog class called Rayne, set its properties accordingly, and use the methods defined by the class to interact with Rayne, as shown in Figure 1.

Figure 1: The methods defined by the class interact with the object.

This is just a simple example to help you visualize what OOP is all about. In the next few sections, we'll cover properties and methods in greater detail, and talk about classes and class instances, scope, events, and even inheritance.

Properties
As we've seen, properties are characteristics shared by all objects of a particular class. In the case of our example, the following properties might be used to describe any given dog:
Color
Height
Length

In the same way, the more useful ASP.NET Button class exposes properties, including:
Width
Height
ID
Text
ForeColor
BackColor

Unfortunately for me, if I get sick of Rayne's color, I can't change it. ASP.NET objects, on the other hand, let us change their properties very easily in the same way that we set variables. For instance, we've already used properties when setting text for the Label control, which is actually an object of the Label class in the System.Web.UI.WebControls namespace:

(VB.NET)
lblMyText.Text = "Hello World"

(C#)
lblMyText.Text = "Hello World";

In this example we're using a Label control called lblMyText. Remember, ASP.NET is all about controls, and, as it's built on OOP, all control types are represented as classes. In fact, all interaction with ASP.NET pages is handled via controls. When we place a control on a page, we give it a name through its id attribute, and this ID then serves as the name of the control. Rayne is an object. His name, or ID, is Rayne. Rayne has a height of 18. The same holds true for the Label control. The Label control's name or ID in the previous example is lblMyText. Next, we use the dot operator (.) to access the Text property that the object exposes and set it to the string "Hello World."

Methods
With our dog example, we can make a particular dog do things by calling commands. If I want Rayne to sit, I tell him to sit. If I want Rayne to lie down, I tell him to lie down. In object-oriented terms, I tell him what I want him to do by calling a predefined command or method, and a resulting action is performed. In VB.NET or C#, we would write this as rayne.Sit, or rayne.LieDown.

As Web developers, we frequently call methods when a given event occurs. For instance, we can take information from an Access database and create an object called objConn to represent the connection to the database. We then open the connection by calling the Open method on that object as follows:

(VB.NET)
Dim objConn As New OleDbConnection( _
"Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Database\books.mdb")
...
objConn.Open()

We say that the Open method is exposed by the connection object, and that we're calling the Open method on the OleDbConnection object stored in objConn. We don't need to know what dark secrets the method uses to do its magic; all we need to know is its name and its purpose.

Classes
You can think of a class as a template for building as many objects as you like of a particular type. When you create an instance of a class, you are creating an object of that class, and the new object has all the characteristics and behaviors (properties and methods) defined by the class.

In our dog example, Rayne was an instance of the Dog class, as shown in Figure 2.

Figure 2: A class serves as the blueprint for an object.

We see that Rayne is an object of class Dog. In our code, we could create a new instance of the Dog class, call it rayne, and use all the properties and methods exposed by the object.

In OOP, when we create new instances of a class, we say we're instantiating that class. For instance (no pun intended!), if we need to programmatically create a new instance of the Button control class, we could write the following code:

(VB.NET)
Dim myButton As New Button()

(C#)
Button myButton = new Button();

As you can see, we've essentially created a new object called myButton from the Button class. We can then access the properties and methods that Button exposes through our new instance:

(VB.NET)
myButton.Text = "Click Me!"

(C#)
myButton.Text = "Click Me!";

Scope
You should now have a concept of programming objects as entities that exist in a program and are manipulated through the methods and properties they expose. However, in some cases, we want to create methods to use inside our class, which are not available when that class is used in code. Let's return to the Dog class to illustrate this concept.

Imagine we're writing the Sit method inside this class, and we realize that before the dog can sit, it has to shuffle its back paws forward a little (bear with me on this one). We could create a method called ShufflePaws, then call that method from inside the Sit method. However, we don't want code in an ASP.NET page or in some other class to call this method - it'd just be silly. We can prevent this by controlling the scope of that method.

The two types of scope available in VB.NET and C# that you should know about are:
Public. Defining a property or method of a class as public allows that property or method to be called from outside the class itself. In other words, if an instance of this class is created inside another object (remember, too, that ASP.NET pages themselves are objects), public methods and properties are freely available to the code that created it. This is the default scope in VB.NET and C# classes.
Private. If a property or method of a class is private, it cannot be used from outside the class itself. If an instance of this class is created inside an object of a different class, the creating object has no access to private methods or properties of the created object.

Events
Events occur when a control object sends a message in response to some change that has happened to it. Generally, these changes occur as the result of user interaction with the control in the browser. For instance, when a button is clicked, a Click event is raised, and we can handle that event to perform some action. The object that triggers the event is referred to as the event sender; the object that receives the event is referred to as the event receiver.

Understanding Inheritance
Inheritance refers to the ability of one class to use properties and methods exposed by another class. In our dog example, we first created a class named Dog, then created instances of that class to represent individual dogs. However, dogs are types of animals, and many characteristics of dogs are shared by all (or most) animals. For instance, Rayne has four legs, two ears, one nose, two eyes, etc. It might be better, then, for us to create a base class named Animal. When we then define the Dog class, it would inherit from the Animal class, and all public properties and methods of Animal would be available to instances of the Dog class.

Similarly, we could create a new class based on the Dog class. In programming circles, this is called deriving a subclass from Dog. For instance, we might create a class for Australian Shepherd and one for my other dog Amigo, named Chihuahua, both of which would inherit the properties and methods of the Dog base class, and define new ones specific to each breed.

Don't worry too much if this is still a little unclear. The best way to appreciate inheritance is to see it used in a real program. The most obvious use of inheritance in ASP.NET comes with the technique of code-behind.

Search