ASP.net button clears cell colors before they are detected

Hi

I have an ASP.net button that runs code that checks the cell backcolors.
The problem is that none of the cell colors are detected as blue because they were cleared on a postback before
the code runs. How do I run the VB.net code before the colors are cleared?
    Protected Sub btnSaveChanges_Click(sender As Object, e As EventArgs) Handles btnSaveChanges.Click

        Try

            Me.lblSaveChangesError.Text = ""
            Dim oDateList As String = TryCast(Session("oDateList"), String)
            Dim arrDates As Object = Split(oDateList, ",")
            Dim oNumberDays As Integer = UBound(arrDates) + 1
            Dim oTextColumnName As String
            Dim oColumnIndex As Integer
            Dim oCellValue As String
            Dim oToolTip As String
            Dim T As TextBox
            Dim oBackColor As System.Drawing.Color

            For r As Integer = 0 To Me.GridView1.Rows.Count - 1
                For d As Integer = 1 To oNumberDays
                    oColumnIndex = d + 1 'First column index is 2
                    oBackColor = Me.GridView1.Rows(r).Cells(oColumnIndex).BackColor
                    If oBackColor = System.Drawing.Color.Blue Then
                        'so if cell ccolor is blue....
                        oTextColumnName = "D" & CStr(d)
                        T = Me.GridView1.Rows(r).FindControl(oTextColumnName)
                        oCellValue = T.Text
                        oToolTip = T.ToolTip

                    End If
                Next d
            Next r


        Catch ex As Exception
            Me.lblSaveChangesError.Text = ex.Message
        End Try
    End Sub

Open in new window

Murray BrownHead DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chinmay PatelChief Technology NinjaCommented:
Hi Murray,

In your page_load, you can write code like this:
If Not IsPostback Then
' Call the code that needs to run before your page is lost.
End If

Open in new window


You will have to take out that grid processing code and create a function which does this processing and call it from the Page_Load.
Another thing you can do is, EnableViewState for a given page/control to true that way it will preserve the values which were set by user interaction/client side scripts. Refer to: https://docs.microsoft.com/en-us/dotnet/api/system.web.ui.control.enableviewstate?view=netframework-4.8

Regards,
Chinmay.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Murray BrownHead DeveloperAuthor Commented:
ok..great
thanks very much
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.