Click here to Skip to main content
15,891,431 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

VB
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    ' Must Set Up Event Handlers each time, even if this is a PostBack
    SetUpEventHandlers()
    SetUpLookUpDialogs()
    SetUpCulture()

    If Page.IsPostBack Then Exit Sub

    ' Show and Enable Action Buttons on WorkflowFrameCommon
    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:

VB
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.

VB
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
Posted
Updated 28-Sep-10 0:11am
v3
Comments
Richard A. Dalton 28-Sep-10 6:28am    
OK. I've narrowed this down a bit and can give a much shorter version of my problem.

I have a text box, with an TextChanged event handler, it doesn't matter whether I use AddHandler or simple used the Handles clause on the event itself.

Whether or not that event handler fires at all can be affected by assigning a value to the text property of a completely unrelated textbox.

-Rd

1 solution

OK, I officially give up trying to figure out what that unrelated line of code was doing.

I have worked around this problem, or perhaps I've been backed into a corner of doing it right despite myself.

The Text boxes that need validation are now each in their own ValidationGroup. I had left validation group blank on all controls because I didn't mind if they were all validated together. It worked fine for controls can have client side only validation.

These currency text boxes need to do an AutoPostback and server validation and that doesn't seem to play nice unless I put it in it's own ValidationGroup.

Why? I don't know. I don't care?

Now my new problem is that if I'm in one of these currency text boxes and I Hit the save button, the AutoPostback fires for the Textchanged of the textbox, but the save functionality doesn't fire.

So, I get a page reload from the AutoPost back on the textbox, making it look like something has happened, but unless you hit save again, nothing gets saved.

Gawd I hate ASP.Net

-Rd
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900