Question : How do I combine the same methods used in 5 different Code behind files?

I have 5 ASP.NET pages with 5 code behind pages. Each VB code behind page is essentially the same at this time. I have 4 methods, 2 of which are shown in the attachment. Each of the ASP.NET pages inherits the same name (Dcops_Maint), though I suppose they could each be different names. How can I combine these 5 partial classes so that I have one common page of 4 methods, which could be used by any of the 5 pages?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Partial Class Dcops_Maint
    Inherits System.Web.UI.Page

    Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, _
                                     ByVal e As DetailsViewInsertedEventArgs) _
                                     Handles DetailsView1.ItemInserted
        If e.AffectedRows = 0 Then
            If (e.Exception.Message.IndexOf("Violation of PRIMARY KEY") >= 0) Then
                'Duplicate key error is SqlException Number = 2601
                lblDetailsViewMessage.Text = "Record Already Exists in the database"
            Else
                ' "Error occurred when inserting:"
                lblDetailsViewMessage.Text = e.Exception.Message.ToString()
            End If
            lblDetailsViewMessage.Style.Value = "font-weight: bold; font-size: 13px;" _
                & "color: red; font-style: italic; font-family: Cambria"
            e.ExceptionHandled = True
            e.KeepInInsertMode = True
        Else
            lblDetailsViewMessage.Text = ""
        End If

    End Sub

    Protected Sub DetailsView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.Load
        lblDetailsViewMessage.Text = ""
    End Sub
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
Partial Class Dcops_Maint
    Inherits System.Web.UI.Page

    Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, _
                                     ByVal e As DetailsViewInsertedEventArgs) _
                                     Handles DetailsView1.ItemInserted
        If e.AffectedRows = 0 Then
            If (e.Exception.Message.IndexOf("Violation of PRIMARY KEY") >= 0) Then
                'Duplicate key error is SqlException Number = 2601
                lblDetailsViewMessage.Text = "Record Already Exists in the database"
            Else
                ' "Error occurred when inserting:"
                lblDetailsViewMessage.Text = e.Exception.Message.ToString()
            End If
            lblDetailsViewMessage.Style.Value = "font-weight: bold; font-size: 13px;" _
                & "color: red; font-style: italic; font-family: Cambria"
            e.ExceptionHandled = True
            e.KeepInInsertMode = True
        Else
            lblDetailsViewMessage.Text = ""
        End If

    End Sub

    Protected Sub DetailsView1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView1.Load
        lblDetailsViewMessage.Text = ""
    End Sub

Answer : How do I combine the same methods used in 5 different Code behind files?

Well, all this commotion, and it turns out he just had an over zealous firewall program (that I wasn't initially aware he had installed) that decided the server was trying to attack his computer, and blocked all access to it. I have configured it as a trusted site now, so this problem shouldn't happen again...
Random Solutions  
 
programming4us programming4us