I have a page that contains a form for editing details of a deal.
If the form receives a deal number in it's querystring it knows it's editing an existing deal. If not it's a new deal.
So far so good.
I have some validators set up on the form.
My problem is that the validators are behaving differently depending on whether this is a new deal or an existing deal. Also the text changed event for some text boxes fire or don't fire based on the same new/old situation.
In short, when the text changes in one of my text boxes, when editing an existing deal everything works. For New deals all the other validators fire, exept the one you'd expect.
I kid you not.
So what? Figure out what different code runs for an existing deal and that'll show you what's wrong.
Well. I've narrowed down the problem by commenting out lines of code until I found a specific line of code that can toggle the bad behaviour on and off when editing an existing record. And it's a completely meaningless line of code, completely unconnected to the Textbox that's causing the trouble.
Here's as much of the code as I can get up here right now, if anyone needs more I'll post it. I almost don't care about the bug any more, It's the challenge of figuring out what the hell is going on.
Here's my page load:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
SetUpEventHandlers()
SetUpLookUpDialogs()
SetUpCulture()
If Page.IsPostBack Then Exit Sub
Master.ShowButtons(WorkflowFrameCommonButtons.All)
Master.EnableButtons(WorkflowFrameCommonButtons.Home + WorkflowFrameCommonButtons.Save)
LoadDropDowns()
DealToScreen(GetDealFromQueryString())
End Sub
Everything before that last line of code works fine.
The trigger line of code is inside DealToScreen.
GetDealFromQueryString returns a Deal object which is either the existing deal, or a brand new deal:
Private Function GetDealFromQueryString() As PipelineDeal
If Request.QueryString("DealNumber") Is Nothing Then
Return New PipelineDeal
Else
Dim dal As New PipelineDAL(SQLServerDataConnection.GetConnection())
Return dal.SelectById(Request.QueryString("DealNumber"))
End If
End Function
DealToScreen itself simply takes the properties of the Deal Object and sticks the values into the text boxes on the screen.
Here's the thing. One of those simple lines of code screws up my validation.
Me.txtClientProjectName.Text = deal.ClientProjectName
ClientProjectName is a simple string property.
As to what specifically is happening/not happening:
I have set up an event handler for a completely different textbox,
not the one mentioned above.
The SetUpEventHandlers seen in the page load above takes care of setting that up:
AddHandler target.TextChanged, AddressOf CurrencyChanged
Depending on whether or not I comment out the simple assignment line of code in DealToScreen, this event handler will fire or not.
Now, at this point you are thinking there's something else I'm not telling you. Something else I'm changing. There isn't.
But it gets worse.
I can toggle the bad behaviour on and off by commenting out the assignment line when editing an existing record.
So, I try toggling the behaviour on and off when creating a new record.
I can't.
The line of code that I comment out runs whether it's a New deal or an existing deal. The only difference is that for a new deal deal.ClientProjectName is Nothing.
So I hard code an actual string value, hoping to get the good behaviour when creating a new deal.
Nothing. It doesn't work.
I'm not expecting anyone to know the solution to this without sitting here and looking at it, but have you ever seen this kind of behaviour?
I've tried reboots etc.
Last night I checked into a hotel called "My Wits End" and I don't think I'll be checking out any time soon.
-Rd