Solved

ASP.NET : How to highlight differences between two form views with the same text boxes between them

Posted on 2014-10-04
7
433 Views
Last Modified: 2014-10-05
I have two FormViews on a web page:  One shows a row of data (fields, columns) from a database table, the other the same row of data.  The difference between them is that one of the FormViews show one or more fields that a user changed (Updates to the record).  I want to highlight in one or both of the FormViews, which pair(s) of the same fields are different between them.

Example:

FormView1.................................................FormView2
Name: Joe                                                Name: Joe
Phone Num: 800-999-9999                  Phone Num: 888-999-9999
etc.                                                            etc.

I would like to highlight the phone number because it's been updated.  The real FormViews will have many fields so it's not easy for someone looking at the two FormViews to spot any changes unlike in the trivial example above.

How to approach this problem or some code (VB or C# is ok) would be appreciated. Thanks!
0
Comment
Question by:Brad Aberg
  • 4
  • 3
7 Comments
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40361768
Recently, I used a similar concept in my application. This was for a WinForm but I am sure it could be adapted for use in asp.net (vb.net), declare:    

'To  initialize with the 2nd column textbox control names and their matching value pairs (in not postback)  
Dim dataPair As New Dictionary(Of String, String)  

'To  initialize with the 2nd column textbox control names and True (in not postback)                      
Dim boldataPairMatching As New Dictionary(Of String, Boolean)  

Form this point on, you caan revise the following winform code to suit your needs (in postback):
   Private Sub TestRevised(sender As Object, e As EventArgs) Handles FirstNameTextBox.TextChanged, LastNameTextBox.TextChanged, AddressTextBox.TextChanged, _
         CityTextBox.TextChanged, StateTextBox.TextChanged, ZipCodeTextBox.TextChanged, PhoneTextBox.TextChanged, EmailTextBox.TextChanged

        Try

            ' find if any of the text boxes has be modified
            ' to enable/disable btnSave accordingly
            Dim bolSaveYN As Boolean = False
            Dim txt As TextBox = TryCast(sender, TextBox)

            If bolSaveNew Then Exit Sub

            If bolChangeText = True Then
                If dataPair.Item(txt.Name) = txt.Text Then 'same as old value
                    boldataPairMatching(txt.Name) = True
                Else
                    boldataPairMatching(txt.Name) = False
                End If
            End If

            For Each pair In boldataPairMatching
                If pair.Value = False Then
                    bolSaveYN = True
                End If
                ' MessageBox.Show(intEdits & ", " & dataPair.Item(txt.Name) & ", " & txt.Text)
            Next

            Me.btnSave.Enabled = bolSaveYN

        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

    End Sub

Open in new window

Mike
0
 
LVL 33

Accepted Solution

by:
Mike Eghtebas earned 500 total points
ID: 40361774
Below, I tried to modify to suit your need. But it needs more massaging:
  
        Try
            ' somehow, store text boxt control just edited in txt
            Dim txt As TextBox = TryCast(sender, TextBox)

            ' compare to see the value is the same
            If dataPair.Item(txt.Name) = txt.Text Then 
                boldataPairMatching(txt.Name) = True    'same for txt
            Else
                boldataPairMatching(txt.Name) = False   'not the same for txt
            End If

            ' loop thru
            For Each pair In boldataPairMatching
                If pair.Value = False Then
                   'remove the red border
                Else
                   'make border re
                End If
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try

BTW, this is how I initialized my dictionary variables:
       Try
            ' first time FirstNameTexBox gets focuses dataPair gets intilized and
            ' bolLoadDictionaryYN gets set to false to prevent updating dataPair dictionary
            If bolLoadDictionaryYN Then
                dataPair.Add("FirstNameTextBox", Me.FirstNameTextBox.Text)
                dataPair.Add("LastNameTextBox", Me.LastNameTextBox.Text)
                dataPair.Add("AddressTextBox", Me.AddressTextBox.Text)
                dataPair.Add("CityTextBox", Me.CityTextBox.Text)
                dataPair.Add("StateTextBox", Me.StateTextBox.Text)
                dataPair.Add("ZipCodeTextBox", Me.ZipCodeTextBox.Text)
                dataPair.Add("PhoneTextBox", Me.PhoneTextBox.Text)
                dataPair.Add("EmailTextBox", Me.EmailTextBox.Text) 'boldataPair

                ' with intial bolChangeText = false to prevent text box change event  
                ' firing when the form gets first uploads 
                boldataPairMatching.Add("FirstNameTextBox", True)
                boldataPairMatching.Add("LastNameTextBox", True)
                boldataPairMatching.Add("AddressTextBox", True)
                boldataPairMatching.Add("CityTextBox", True)
                boldataPairMatching.Add("StateTextBox", True)
                boldataPairMatching.Add("ZipCodeTextBox", True)
                boldataPairMatching.Add("PhoneTextBox", True)
                boldataPairMatching.Add("EmailTextBox", True)
            End If

Open in new window

0
 

Author Comment

by:Brad Aberg
ID: 40361810
This is great.  Thank you very much eghtebas (Mike).
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Closing Comment

by:Brad Aberg
ID: 40361811
Thanks!  This was my first question on Experts-Exchange.  I appreciate your detailed answer.
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40361813
Do you mind sharing your solution? I am sure there are lots I could learn from you. In particular, I want to to know how you got control names? etc.

Thanks,

Mike
0
 

Author Comment

by:Brad Aberg
ID: 40362482
Mike,

My code is pretty simple and basic because I am a beginner at ASP.NET.  Here's a snippet showing comparison of one pair of textbox text contents.

Protected Sub SqlDataSource3_Load(sender As Object, e As EventArgs) Handles SqlDataSource3.Load
    Dim foo As TextBox = TryCast(FormView1.FindControl("LastNameTextBox"), TextBox)
    Dim bar As TextBox = TryCast(FormView2.FindControl("LastNameTextBox"), TextBox)
    If foo IsNot Nothing Then

      If bar IsNot Nothing Then

        If foo.Text <> bar.Text Then

          bar.BackColor = Drawing.Color.Yellow
          foo.BackColor = Drawing.Color.Yellow

        End If
      End If
End Sub

Open in new window


Tomorrow I am going to see if I can use your more sophisticated answer to improve my code.  The way my code is n ow, I'll have to include lines for every pair of textboxes in the formview (about 35 or so).  If I can use to loop through I will have a more elegant solution. Thanks again.
0
 
LVL 33

Expert Comment

by:Mike Eghtebas
ID: 40362715
Oh, I thought you already have it finalized. Yes looping through the text boxes is the way to go.

If you decided to post a new question on the text boxes, add a link here so I could post a solution.

Mike
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Is there a way to programmatically restart a VB.Net application when an exception occurs? 8 48
vb.net 2 37
Syntax Error 2 46
Exit the loop 4 35
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now