The Forums on slxdeveloper.com are now retired. The forum archive will remain available for the time being. Thank you for your participation on slxdeveloper.com!
|
|
DateTimePicker returned date
Posted: 17 May 10 6:12 AM
|
Hi all, this one is killing me! I created a form with multiple datetime pickers on it in AA and have taken it into Visual Studio (we use visual web developer but basically same thing).
I am trying to capture the event of the calender closing when the user chooses a date but im having problems.
I can use the OnDateTimeValueChanged event but this does not fire unless you choose a date, leave the datetimepicker box and then go back into it! What i need is an if statement fired off as soon as the user picks a date and depending on the result of the if statement the date they just chose is removed.
Thanks all. |
|
|
|
Re: DateTimePicker returned date
Posted: 17 May 10 6:42 AM
|
UPDATE: just realised its not the leaving and re-entering of the datetime picker box that fires the event. It happens when i enter and leave a text box that has an onblur event on it that calls javascript to invoke a button click. Whyen the onblur of a text box fires the datetime picker recognises that its value has chnaged. But i need it to do this as soon as the calender closes |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 3:47 AM
|
OK not had to do that one before, but what I would first attempt is "attaching" an onchange event to the textbox that holds the date on the screen. This will only fire when the date is changed mind...
Within javascript we have an attachEvent method. So firstly get the id of the "textbox" portion of the datetimepicker, which should be something along the lines of:
string id = ((TextBox)dMYDATETIMEPICKER.Controls[0]).ClientID;
(I am assuming the first control in the SLX datetimepicker control collection is a textbox, you will have to double check...)
Then add some javascript to the page in a quickformload (make sure it is a repaint event):
string scriptFunction = "function dtpChange() { alert('test'); }"; ScriptManager.RegisterClientScriptBlock(this, GetType(),"key1", scriptFunction, true);
string script = "$(document).ready(function() { var fld = document.getElementById('" + id + "'); if (fld.attachEvent) { fld.attachEvent('onchange',dtpChange); } }); "; ScriptManager.RegisterClientScriptBlock(this, GetType(),"key2", script, true);
Again, syntax could be a bit off
Here is breakdown of the method:
http://javascript.about.com/library/bldom20.htm
You cannot pass parameters, there is a special way of doing this, something on here:
http://bytes.com/topic/javascript/answers/534673-attachevent-arguments
Thanks, Nick |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 4:03 AM
|
Hi Nick,
Thanks for your reply. I can now capture the event when the date is chosen (i swear i tried everything with auto postback before but revisited it and this time is worked for some reason!)
But now i have a new problem when trying to blank out the date. Ive tried:
opportunity.ZOpportunityExts.ZPQQSent.Value = DBNull.Value; opportunity.ZOpportunityExts.ZPQQSent = ""; opportunity.ZOpportunityExts.ZPQQSent.Value = null;
and every possible combination i can think of but i always get a conversion error with the whatever data type and System.DateTime. How do you go about blanking out the date? If i just try to refer to the control, so ZPPQSent.Text = "", it does nothing. |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 4:26 AM
|
OK - cool I thought that should have worked 
I'm sure its just:
opportunity.ZOpportunityExts.ZPQQSent = null;
Thanks, Nick |
|
|
| |
|
Re: DateTimePicker returned date
Posted: 18 May 10 4:42 AM
|
just out of curiousity i tried: opportunity.ZOpportunityExts.ZPQQSent = DateTime.MinValue;
but nothing happened. maybe opportunity.ZOpportunityExts.ZPQQSent = null; is the correct line but the box is not updating automatically as im expecting?
|
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 5:05 AM
|
ive also tried doing an sql update to null out the field in the database the datetimepicker is bound to but it didnt work. strange since i did the exact same thing to automatically tick the disabled complete tick boxes on a sales process which worked. |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 5:13 AM
|
Its definitely just set the property to null.
The datepicker is correctly bound? (to the DateTime object)?
There are no quickformloads re-setting the value anywhere? |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 6:19 AM
|
I dont think the value is being reset anywhere, this is the only occasion i refer to these datetime pickers in code other than the bindings. I assume and think the bindings are correct as that was all done in AA before i opened the form in Visual web developer and the bindings seem fine.
Ill try summing everything up:
The first time the tab is used - I choose a date from the date time picker, i hit my if and the message displays, when i look at the database at this point the field the datetimepicker is linked to is still NULL as i havent saved yet so me executing sql at this point to set the field to NULL was pointlesss (lol!).
So what property of the datetimepicker is holding the date value i just chose if the database field is still null? is there any way i can tell the datetimepicker to 're-pull' down the value in its bound db field so it will replace the date with null?
Also if i message box out opportunity.ZOpportunityExts.ZPQQSent.ToString() it displays the current value in the database rather than the value in the text box. I can set the database value to null with sql its getting this to refresh visually thats killing me.
Im really confused. |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 6:35 AM
|
When you say you assume and think the bindings are correct are you totally sure? I have NEVER seen a binding not reflect a change made to the property (unless there is other code updating it).
Double check in AA that the property is bound to the DateTimeValue of the date time picker (and NOT to the Text, or anything else). When you message box as you have said and it shows the value in the database this agian leads me to believe your binding has to be wrong..
Send me the quickform code if you want me to double check it - just message me through this site.
Cheers,
Nick |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 6:40 AM
|
Thanks for all this help Nick, im still new to the 7.5 web way of coding but is this the line/s youre looking for:
// ZPQQSent.DateTimeValue Binding Sage.Platform.WebPortal.Binding.WebEntityBinding ZPQQSentDateTimeValueBinding = new Sage.Platform.WebPortal.Binding.WebEntityBinding("ZOpportunityExts.ZPQQSent", ZPQQSent, "DateTimeValue"); BindingSource.Bindings.Add(ZPQQSentDateTimeValueBinding);
ill still send through the whole code if you think it will help? |
|
|
| |
|
Re: DateTimePicker returned date
Posted: 18 May 10 8:21 AM
|
yet another datetime picker question....... how can i force users to use the calender and stop them free typing in the box? Read-Only loses the calender. |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 8:27 AM
|
Along a similar line to the earlier post - get the textbox portion of the datepicker control
TextBox txtBoxPortion = (TextBox)MYDATEPICKER.Controls[0];
txtBoxPortion.ReadOnly = true;
If that doesnt work add some javascript to the page that will update the textbox portion of the datepicker (similar to my earlier post).
Thanks, Nick |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 10:01 AM
|
May have found a different way to approach this Nick.
I used your code: TextBox txtBoxPortion = (TextBox)MYDATEPICKER.Controls[0]; txtBoxPortion.ReadOnly = true;
to add an onclick event to the calender image of the datetimepicker control so i can now do my If statement BEFORE a date is actually chosen. Now i need to figure out how to stop the calender from popping up when my if stament is hit.
Ideas anyone? |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 10:07 AM
|
You could try ending your code with a return false; This should halt the execution of the click at that point, and not carry on with opening the dialog. Although I am not sure how the events are wired up for the datepicker....
Cheers, Nick |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 10:36 AM
|
absolute....legend. worked a treat. one FINAL thing i need to know, up to this point ive only been calling javascript on control attributes, so OnClick call javascript, onKeyPress call javascript etc.....
how do you call javascript just in the regular c# code? So somthing like:
if (a=1) { 'Call javascript function 1' } else{ 'Call javascript function 2' }
Im sure its linked to your earlier reply Nick but i cant quite get my head around the syntax.
|
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 10:40 AM
|
Coolio...
When you say "call javascript" what exactly do you mean? If you are within C# you are now server side so you cant really call any javascript per se. You can send some javascript back to the client to run (using a ScriptManager.RegisterStartupScript) but I am sure there is a better way if you describe exactly what you want to achieve.
Cheers, Nick |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 10:49 AM
|
Ok here goes..... by adding an on click event to the calender image i can call the javascript and return false in the javascript to stop the calender popping up BUT as things stand this happens every time the image is clicked regardless of whats going on in the rest of the form. I need two separate possibilities, so basically in my head its:
1. Calender image clicked --> calls javascript function1 2. javascript function1 --> invokes a button click that performs my if statement checking some control values on the page. 3. If we hit true on my if statement then call javascript function2 that returns false to stop the calender popping up else let the datetimepicker continue as normal.
unless im going completely the wrong way and overcomplicating it!! |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 10:55 AM
|
I want to add a couple of comments:
The Calendar control invokes script that creates the dialog window on the client side, so it is almost impossible to get a reference to the Ok button (its ID will be something like ext-gen212).
I would suggest you try other Events on either the Textbox or the Hidden control that holds the data (sometimes I have more luck on the hidden control, since the Textbox has events already hooked into, and it is a bit difficult to then add additional event handlers (although that could be done, and you could decide the order on which the Handlers fire)).
For the Date control, it has a hidden Input control called _Hidden that also stores the value and you could also attach to its events.
I would suggest trying the onpropertychange event, and use an if statement to only act if the value property is changed.
Use IE Developer Toolbar (or something similar) to explore the objects on the Page and how they are created, then you can interact much easier with them either via JavaScript or C#. |
|
|
|
Re: DateTimePicker returned date
Posted: 18 May 10 11:00 AM
|
Well if you want to keep it all client side with no postbacks then you have to send javascript functions 1 and 2 to the screen, in a Page_load (or "repaint" quickformload).
Use ScriptManager.RegisterClientScriptBlock to get the functions there.
Then your onclick event can call these two functions as required. You can check form field properties within the javascript onclick as well, so within this check decide whether to call javascript function 1 or 2. If that makes sense...
This probably is very overcomplicated though - not sure of the overall requirement for the system but there must be an easier way. That said if you get the logic working as above it will be nice and responsive keeping it all client side. Re-usable on other screens too if you keep the javascript methods generic. |
|
|
|