Welcome Guest Search | Active Topics | Sign In | Register

DatePicker created using server side vb trying to get the value of the date selected from the reques Options
Don
Posted: Thursday, March 27, 2008 1:34:46 PM
Rank: Newbie
Groups: Member

Joined: 3/27/2008
Posts: 5
I'm creating date picker controls using server side code.
The datepicker is created and seems to work fine.
But I can't get at the date the client selected using the code behind for the page unless I put the date picker in the page itself, without using code.
I'm using the demo version we are thinking about buying.
Thanks,
D
eo_support
Posted: Thursday, March 27, 2008 1:42:33 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

First you would need to make sure your dynamic loading works fine:

http://www.essentialobjects.com/Forum/Default.aspx?g=posts&t=347

The key is when your page comes back, you must recreate it. The above post explained this in detail.

Once you recreate it, you will have a reference of your DatePicker control. You will then be able to get the date user selected through its SelectedDate property.

Feel free to let us know if you have any more questions.

Thanks
Don
Posted: Thursday, March 27, 2008 1:55:44 PM
Rank: Newbie
Groups: Member

Joined: 3/27/2008
Posts: 5
I appreciate your quick response.
However, just about everything on the page is created using code.
Test boxes, cells, tables, drop down lists check boxes and now, the datepicker control.
Everything else I can create it, apply it to the page, render the page, and get a value entered by the client when the page is posted. Except the date picker control.
Dim dtp As New EO.Web.DatePicker
'Dim dtp As New Object

dtp.ID = "txt" & ControlName
dtp.AllowMultiSelect = False
dtp.BackColor = Drawing.Color.White
dtp.Enabled = True
dtp.ClientSideOnSelect = "SetDate"
'dtp.DisableTextBox = True
dtp.TodayStyle.CssText = "font-family: tahoma; font-size: 12px; border-right: #bb5503 1px solid; border-top: #bb5503 1px solid; border-left: #bb5503 1px solid; border-bottom: #bb5503 1px solid"
dtp.SelectedDayStyle.CssText = "font-family: tahoma; font-size: 12px; background-color: #fbe694; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid"
dtp.DisabledDayStyle.CssText = "font-family: tahoma; font-size: 12px; color: gray; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid"
dtp.PickerStyle.CssText = "padding-left:2px; padding-right: 2px;"
dtp.CalendarStyle.CssText = "background-color: white; border-right: #7f9db9 1px solid; padding-right: 4px; border-top: #7f9db9 1px solid; padding-left: 4px; font-size: 12px; padding-bottom: 4px; border-left: #7f9db9 1px solid; padding-top: 4px; border-bottom: #7f9db9 1px solid; font-family: tahoma"
dtp.TitleArrowStyle.CssText = "cursor:hand"
dtp.DayHoverStyle.CssText = "font-family: tahoma; font-size: 12px; border-right: #fbe694 1px solid; border-top: #fbe694 1px solid; border-left: #fbe694 1px solid; border-bottom: #fbe694 1px solid"
dtp.MonthStyle.CssText = "font-family: tahoma; font-size: 12px; margin-left: 14px; cursor: hand; margin-right: 14px"
dtp.TitleStyle.CssText = "background-color:#9ebef5;font-family:Tahoma;font-size:12px;padding-bottom:2px;padding-left:6px;padding-right:6px;padding-top:2px;"
dtp.OtherMonthDayStyle.CssText = "font-family: tahoma; font-size: 12px; color: gray; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid"
dtp.DayHeaderStyle.CssText = "font-family: tahoma; font-size: 12px; border-bottom: #aca899 1px solid"
dtp.DayStyle.CssText = "font-family: tahoma; font-size: 12px; border-right: white 1px solid; border-top: white 1px solid; border-left: white 1px solid; border-bottom: white 1px solid"
If IsDate(ControlValue) Then
dtp.SelectedDate = ControlValue
End If
Return dtp
I tried (as you might be able to see) to use the clientonselect to pass the value in so I can at least save it to hidden storage but I can't pass a value into the script.
Will I Need to handle this EO control differently than the other standard controls when trying to get the value the client entered from the calendar? Why is this control not functioning like the other controls on my page?
eo_support
Posted: Thursday, March 27, 2008 2:11:10 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

You mentioned about "get a value entered by the client when the page is posted". How do you get the value?

There are generally two ways to get a value client side entered:

1. Use the control itself. For example, by TextBox1.Text;

2. Use the form variable. For example, by Request.Form.Items("TextBox1");

Both should work with our Calendar, however the differences are:

1. For Calendar if you use the first method (that would be DatePicker.SelectedDate), you will get a DateTime object. The second method will give you a string. So if you use the second method, you would need to convert the string back to a date by yourself if other part of your code needs a date value;

2. While you can use Request.Form.Items("TextBox1") to get control "TextBox1"’s content, you will not be able to use Request.Form.Items("DatePicker1") to get the “DatePicker1”'s content. DatePicker is a rather complex control and the textbox is only a part of it. So instead of using Request.Form.Items("DatePicker1"), you should use Request.Form.Items("_eo_DatePicker1_Picker") instead;

The above differences apply regardless the DatePicker is dynamically created or not.

Using ClientSideOnSelect should always work. I am not sure what you mean by "can't pass a value into the script."?

Thanks
Don
Posted: Thursday, March 27, 2008 2:45:56 PM
Rank: Newbie
Groups: Member

Joined: 3/27/2008
Posts: 5
Hi,

I have tried both option 1 and option 2. Option 1 will only work if I put the control directly in the page from the toolbox. Else it doesn't exist and the code wont even compile because the control isn't there at compile time.
Option 2. I have reviewed the html source code and noticed it puts the _eo_ my control name _picker items on my controls ID. I worked around this by creating a routine where I pass my controls name in and it appends your items (_eo_ and _picker) but I'm still geting "nothing" as the value from the request.form.item(...). I even went as far as creating an object and doing a page.findcontrol but that didn't work either.

In short, I am using the request.form.item.
The html shows
<input style="padding-left:2px;padding-right:2px" type="text" id="_eo_txtActivityDateStart_picker" value=" / / " size="11"/>
As created from the datepicker.
The code I'm using to try get the value is.

Private Function DateTimePickerDate(ByVal vControlName As String) As Date
Dim strD As Object
strD = Request.Form.Item("_eo_" & vControlName & "_picker")
If IsDate(strD) Then
Return strD
Else
Return Nothing
End If
End Function

Which is returning "nothing"
I have also tried page.findcontrol but it doesn't find it.
But remember, there are appx. 26 other items on the form created the same way that I can find using request.form.

Thanks again for your quick response.
If you need more information or if something needs to be setup differnetly please let me know.
Thanks,
D
eo_support
Posted: Thursday, March 27, 2008 3:11:56 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi Don,

As for the first option, the reason you are getting a compiler error is because you did not read my first reply. :) We have been asked about this question many many many times and that post explained exactly why and how.

The second option not working seems to be a bug. It can be easily worked around though. Try do the following:

1. Place a Label at the end of the page. Make sure it's at the end of the page so that it's after the DatePicker:

Code: HTML/ASPX
<asp:Label id="FixupScript" runat="server"></asp:Label>


2. Use that label to render a small segment of JavaScript:

Code: Visual Basic.NET
Dim InputName As String
InputName = "_eo_" + "DatePicker1" + "_Picker"
FixupScript.Text = _
    "<script type=""text/javascript"">" & _
    "document.getElementById(""" & InputName & """).name = """ & InputName & """;" & _
    "</script>"


You will need to replace "DatePicker1" with your control name.

That should allow you to get the value from the DatePicker. We will put also this code in our next build. Sorry about the problem!

Thanks!
Don
Posted: Thursday, March 27, 2008 3:55:54 PM
Rank: Newbie
Groups: Member

Joined: 3/27/2008
Posts: 5
Hi,

The first option wasn't really a question for me. The control doesn't exist on the page therefore I can't explicitly use it in my code behind. Maybe we mis understood each other? ;)

I just tried your work around a couple of different ways and so far I'm still not getting it
But it could be my lack of general knowledge on the subject.

I put a label on the page, added some java to it in the code behind, as in your example. Then I tried adding the label using code after I load the date control. Not sure I"m getting it.
What exactly is going trigger the run of that java code and are you saying that I can now just do a request.form as usual after I put that in to get my value? I'll be back at it tomorrow.

Thanks,
D
eo_support
Posted: Thursday, March 27, 2008 4:57:51 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
Hi,

I believe we understood the first option correctly. It's a very common scenario and we get that a lot. :)

You can either add the label with code or add it in the page. There is no need to do both. Nobody needs to "trigger" the JavaScript code. It runs as long as it's there ---- so all you need to do is to put it there, either dynamically through code, or declaratively in your .aspx file. Once you have that in place, your Request.Form will work as you expected.

If you are still confused, it might be easier for us to show that to you. We can setup an online meeting to show it to you if you are OK with it. Just let us know. Or you can also wait for our next build (which should be a few days away), we will put this code in so everything will automatically work for you.

Thanks
eo_support
Posted: Friday, April 4, 2008 7:45:23 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,218
The fix up JavaScript is merged into build 2007.2.46, so it is no longer needed.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.