Winn.ws

Simple Ajax with .NET

Adding Ajax to an application is simple and easy! Ajax is a powerful tool and can make your application look and feel great!

First let’s start by adding a “Script Manager” to the page, now we only have to add this once so it’s best placed in your Master page. The Script Manager needs to be placed between the form tags on your page like so:

1
2
3
4
<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
</form>

After that, we can now add Ajax to an item. Below I have added an “Update Panel” to a list view. Now every action that list view makes will be way of HTTP Requests “Ajax”!

1
2
3
4
5
6
7
8
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
        <asp:ListView ID="ListView1" runat="server" DataKeyNames="PostID" 
                DataSourceID="ObjectDataSource1">
            ' Your code here...
        </asp:ListView>
    </ContentTemplate>
</asp:UpdatePanel>
posted in: .NET 3.5 VB, Development 11.03.08

Web User Controls

Using the user controls may be one of the best moves you will make when developing an application in .NET. The user control will allow you to separate your reusable logic and keep it in one place. For many developers this is a great thing! Many of us have to re-create items over and over, after some time your code can look like crap and then you feel like crap because you have to deal with it.

Let’s say we have a site where I needed a “Quick Search” on every other page, but each page had a different look and feel or a different CSS document. All I would need to do is create a web user control “.ascx” file and lay down the basics of my quick search. Assign the div’s ID’s or classes, then include your control in each page that needs it. To style, just use your style sheet assigned to that page an add your styles.

Web controls make life a little easier when developing in .NET, so be sure to take advantage of this great tool and stop duplicating your work!

posted in: .NET 3.5 VB, Development 10.23.08

Select Case in VB

For the few still wondering how to do a Select case in VB here you go! Below is your basic select case in a function returning a true or false boolean.

Public Function CheckStatus(ByVal Status As Boolean) As Boolean
        Select Case Status
            Case True
                Return False
            Case Else
                Return True
        End Select
End Function

The function is checking for a true or false then returning it back out, based on the case.

posted in: .NET 3.5 VB, Development 10.18.08

Functions in VB

Something that i picked up on was that functions in VB and functions in PHP are a lot alike! This is great news, VB does not have the huge learning curve when stepping in from PHP.

Below i have created a simple function inside if a class:


Public Class Core
Public Function HelloWorld(AVar)
Return "Hello " & AVar
End Function
End Class

Remember, in VB that if you have a function it will need to return a value but a Sub cant return one.

posted in: .NET 3.5 VB, Development 10.06.08

InsertCommand .NET Date

So, i have been messing with .NET more and more. Just wanted to make a note just in case there is another developer out there looking for this solution. So the problem was i needed to place a date into the database but had no idea. So in the “asp:SqlDataSource” i edited the InsertCommand.


InsertCommand="INSERT INTO [rev1_posts] ([subject], [email], [body], [status], [created_at]) VALUES (@subject, @email, @body, 1, getdate())"

Note i added “getdate()” to grab the current date. Simple i know but it took me some time to find the solution.

posted in: .NET 3.5 VB, Development 09.26.08