When the page loads, it checks to see if the user is trying to update an existing book or create a new book.
Something about my code just doesn't seem right. It feels cumbersome and not very logical. Could someone put me out of my misery and let me know that I wrote this bit ok?
Public Property modID As Int32
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim bookID = Request.QueryString("bookID")
If Not String.IsNullOrWhiteSpace(bookID) Then
newBook = False
Else
newBook = True
Create() 'create a new book
bookID = modID.ToString
End If
If Not newBook Then
commitData() 'saves data on form
End If
If Not IsPostBack And Not newBook Then
Page.DataBind()
populateControls() 'populate my dropdown lists and radio/checkbox controls
populateDatasets() 'load datasets to be used later
End If
End Sub
Public Sub Create()
'create a new book
newBook = False
Using dbcon As New SqlConnection(DBUtilities.ConnectionStringDefault)
dbcon.Open()
Dim cmd As New SqlCommand(CreateSQL, dbcon)
cmd.Parameters.Add(New SqlParameter("@authorID", currentUser))
modID = DirectCast(cmd.ExecuteScalar(), Int32)
End Using
navmod = NavbookFactory.Getbook(CInt(modID))
populateNewBook()
End Sub