want to clear databound textbox after populating


Author
Message
Greg
Greg
StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)
Group: Forum Members
Posts: 7, Visits: 52
I currently have a date textbox that has the bindingfield and businessobjectname properties set, and is populating based on that. However, since I am working with dates, I have set a NULL replacement value in the business object mapper of CDate("1/1/1800").

I would like the textbox to display nothing if the database field has a null value in it, however I have so far been unable to figure out how to clear the textbox if the date is 1/1/1800.

Is there a way to clear the textbox without using javascript? Is there a different value I could be using in the business object mapper for the NULL replacement value?
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Is this a Winform or a ASP.NET app?  If you are using Winforms, there are SF controls designed to handle dates when using a null replacement value. The DateTimePicker has a NullDateValue property and the DateBox has the EmptyValue property. 
Tags
Greg
Greg
StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)
Group: Forum Members
Posts: 7, Visits: 52
this is an ASP.NET app
Greg
Greg
StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)
Group: Forum Members
Posts: 7, Visits: 52
Thanks for the reply, Greg, and thanks for tagging it. I see this post is closest to what I am looking to do: http://forum.strataframe.net/Topic13228.aspx

I am still a little worried about storing 1/1/1800 dates in my database, but I suppose I shouldn't be. There are other instances where this date pops up in the application that I need to handle as well. Hopefully this subclassed control will help me in those situations as well.
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Greg,

You won't be storing 1/1/1800 in the database (or you don't have to), you'll be storing NULL in the database. When you use the BO Mapper to map a datetime field to a column in the database and you use the Null option value of Return Alternate on Null / Set Null on Alternate, this sets the value of the field in the BO to the alternate value (1/1/1800 in this case), but when storing data in the database, if the value in the BO is 1/1/1800, it sends a NULL to the db for storage (See note below).

So, what the post you found (I totally forgot about that one) is saying is that you separate the property you are binding from the property you are displaying. Then you synch the display property and the binding property via events.

Let us know if you run into problems with the sub-classed TextBox.

Details of Alternate Nulls

What is actually happening is that the property in the BO is referencing a column in the underlying DataTable. The property getter checks if the value in the DataTable is DbNull and if it is, it returns the alternate value. In the setter, it checks if the value being set is the alternate value and if it is, it sets the column in the DataTable to DbNull.  Check out the .designer file to see what is actually happening.
Greg
Greg
StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)
Group: Forum Members
Posts: 7, Visits: 52
Thanks for your help, Greg. Can't seem to get the 1/1/1800 to stay out of my database though Sad

Currently I am just using a property (DateValue) to sync the Text values to my Date values. It looks like it works, but I am still getting 1/1/1800s in my database. I am using Set Null on Alternate Value now as well. Currently my alternate value is DateTime.Parse("1/1/1800 12:00:00 AM"). The only thing I did in my subclassed textbox was create the property. Feel like I am missing something small, but I'm not sure what.
Teddy Jensen
Teddy Jensen
StrataFrame Novice (118 reputation)StrataFrame Novice (118 reputation)StrataFrame Novice (118 reputation)StrataFrame Novice (118 reputation)StrataFrame Novice (118 reputation)StrataFrame Novice (118 reputation)StrataFrame Novice (118 reputation)StrataFrame Novice (118 reputation)StrataFrame Novice (118 reputation)
Group: StrataFrame Users
Posts: 52, Visits: 8K
Hi Greg,

I use "new DateTime(1800,1,1)" as alternate value in the bo, and it works for me when using SF datetimepicker.

This just so you maybe could narrow your problem down to the subclassed textbox, if it doesn't work.



/Teddy
Edited 14 Years Ago by Teddy Jensen
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
Teddy right on the money. The web adds some complexity so sometimes it's a good idea to create a mini test project, a SF C# (or VB.NET...whatever you use) Winform app, copy your BO over, and see if it works. If the BO is working, then you have an issue with the TextBox, but likely it is a configuration issue.  I've attached an image showing the settings in the BO mapper.
Attachments
SF.BOMapper.NullSettings.png (153 views, 34.00 KB)
Greg
Greg
StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)StrataFrame Beginner (23 reputation)
Group: Forum Members
Posts: 7, Visits: 52
Oh boy... I feel like an idiot. The problem was that the save() function was being overridden and a stored procedure was taking over. So DUH! I have to pass the DBNull value myself!

Thanks for your help guys BigGrin
Greg McGuffey
Greg McGuffey
Strategic Support Team Member (3.4K reputation)
Group: Forum Members
Posts: 2K, Visits: 6.6K
LOL, glad you got it figured out!
GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search