Click here to Skip to main content
15,896,118 members
Articles / Web Development / ASP.NET

A Simple Blog using a Quick and Easy Saveable Object Class, JSON, and LINQ

Rate me:
Please Sign up or sign in to vote.
2.78/5 (3 votes)
9 Dec 2007CPOL2 min read 20K   124   19  
Learn how to create classes that automatically save and retrieve their data (), and how to quickly query that data with LINQ. The sample implementation of my class Saveable shows just how easy it is to create a blog.

Partial Class Create
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim m As BlogMessage
        If Request("ID") IsNot Nothing Then
            m = BlogMessage.Load(New Guid(Request("ID")))
        Else
            m = New BlogMessage
        End If
        m.Title = TextBox1.Text
        m.Message = TextBox2.Text
        m.Save()

        Response.Redirect("View.aspx?ID=" & m.ID.ToString)
    End Sub

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        If Request("ID") IsNot Nothing And Not Page.IsPostBack Then
            Dim b As BlogMessage = BlogMessage.Load(New Guid(Request("ID")))
            TextBox1.Text = b.Title
            TextBox2.Text = b.Message
            Button1.Text = "Update Post"
            Page.Title = "Update Post"
        End If
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Vortaloptics
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions