Clean up

G

Guest

Thanks to S. Justin Gengo, MCP, I think I have a viable editing senario that
would enable searching etc. The general flow goes like this:
Start on a search screen. Select a record. Edit page is displayed. On
save or cancel the user is returned to the search screen. I'm doing this by
creating two user controls (Search and Edit) and placing them in a multiview
with two views. I've got it working but there's a few things that don't seem
very clean to me and was wondering if there's a better .net ish way to do
this.

The page that holds the views:
Partial Class _Default
Inherits System.Web.UI.Page

Protected Sub Search1_Selected(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Search1.Selected
Edit2.RecordId = Search1.RecordId
Edit2.Edit()
MultiView1.ActiveViewIndex = 1
End Sub

Protected Sub Edit2_Finished(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Edit2.Finished
Search1.Refresh()
MultiView1.ActiveViewIndex = 0
End Sub
End Class


The page that searches:
Partial Class Search
Inherits System.Web.UI.UserControl
Dim _recordId As Integer
Public ReadOnly Property RecordId() As Integer
Get
Return _recordId
End Get
End Property
Protected Sub GridView1_SelectedIndexChanged(ByVal sender As Object, ByVal
e As System.EventArgs) Handles GridView1.SelectedIndexChanged
Dim row As GridViewRow = GridView1.SelectedRow
_recordId = CInt(row.Cells(1).Text)
RaiseEvent Selected(Me, New EventArgs)
End Sub
Public Event Selected As EventHandler
Public Sub Refresh()
GridView1.DataBind()
End Sub
End Class


The page that edits
Partial Class Edit
Inherits System.Web.UI.UserControl
Public Property RecordId() As Integer
'How do I not use an extra textbox that's hidden?
Get
If IsNumeric(TextBox6.Text) Then
Return CInt(TextBox6.Text)
Else
Return 0
End If
End Get
Set(ByVal value As Integer)
' Special textbox just for the primary key
TextBox6.Text = CStr(value)
SqlDataSource1.DataBind()
End Set
End Property
Public Sub Edit()
Me.DetailsView1.ChangeMode(DetailsViewMode.Edit)
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
'Update, how do I know if there was an error and not raise the event?
DetailsView1.UpdateItem(True)
RaiseEvent Finished(Me, New EventArgs)
End Sub
Public Event Finished As EventHandler

Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
System.EventArgs)
DetailsView1.ChangeMode(DetailsViewMode.ReadOnly)
RaiseEvent Finished(Me, New EventArgs)
End Sub
End Class


Any thoughts on cleaning this up a bit and making the search screen control
drive the edit control better are appreciated.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top