Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
435
Moving a webdatepicker
posted

I am upgrading an app from 7.2 to 12.1.  I have changed webdatechooser to a webdatepicker. I have a page with an dynamically built asp table. This table could be 100's of rows long.  TH old version of the app had 1 webdatechooser on it and moved it around the page based clicking an image(of a calendar). I use JavaScript to move the one webdatechooser to appropriate cell and open it there.  In the JavaScript you can see where i try and get elementbyid (which worked before) (on same line you can see some of the other options i have tried commented out with no success). Appending it as a child to the cell gave me this result with webdatechooser.

What this javascript should do when click on image open webdatapicker at the image.

Below is VB code used to generate table (with code for generating cells in bold):

 If intCountRows > 0 Then
                For i = 0 To intCountRows - 1
                    k = i + 1
                    Dim strType As String = CStr(dsDetail.Tables(0).Rows(i).Item("Type_Desc"))
                    Dim intNSS As Integer = dsDetail.Tables(0).Rows(i).Item("Non_Standard_Ship")
                    If LCase(strType) = "capital" Then
                        If dsDetail.Tables(0).Rows(i).Item("Unit_Name") Is System.DBNull.Value Then
                            dsDetail.Tables(0).Rows(i).Item("Unit_Name") = "Each"
                            dsDetail.Tables(0).Rows(i).Item("Qty_per_Unit") = "1"
                        End If
                    End If
                    'Dim table As New Table
                    Dim row As New TableRow
                    Dim cell As New TableCell

                    Me.tblAdminTable.CssClass = "CatalogAdminTable"

                    cell = New TableCell
                    row = New TableRow

                    With cell
                        .CssClass = "AdminRateFAREntry"
                        .HorizontalAlign = HorizontalAlign.Left
                        .Wrap = False
                        Dim img As New WebControls.Image
                        Dim img2 As New WebControls.Image

                        If LCase(strType) = "capital" Or strType = "1" Then
                            img.ImageUrl = "../images/catalog_capital_icon.gif"
                        ElseIf LCase(strType) = "expendable" Or LCase(strType) = "spare parts" _
                        Or strType = "2" Or strType = "3" Then
                            img.ImageUrl = "../images/catalog_expendable_icon.gif"
                        End If

                        .Controls.Add(img)

                        If intNSS <> 0 Then
                            img2.ImageUrl = "../images/truck.gif"
                            .Controls.Add(img2)
                        End If



                        '.Width = Unit.Percentage(17)
                        Dim link As New HyperLink

                        With link
                            .ID = "hypCatID_" & CStr(k) 'dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id")
                            .NavigateUrl = "../Search/CatalogPage.aspx?CatID=" & dsDetail.Tables(0).Rows(i).Item("Cat_ID")
                            .Text = dsDetail.Tables(0).Rows(i).Item("Cat_ID")
                            .Font.Bold = True
                        End With

                        .Controls.Add(link)
                    End With

                    row.Cells.Add(cell)

                    cell = New TableCell

                    With cell
                        .HorizontalAlign = HorizontalAlign.Left
                        .CssClass = "AdminRateFAREntry"
                        ' .Width = Unit.Percentage(40)
                        Dim label As New Label
                        With label
                            .ID = "lblDesc_" & CStr(k) ' dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id")
                            .Text = dsDetail.Tables(0).Rows(i).Item("Cat_Name")
                        End With
                        .Controls.Add(label)

                    End With

                    row.Cells.Add(cell)

                    cell = New TableCell

                    With cell
                        .HorizontalAlign = HorizontalAlign.Left
                        .Wrap = False
                        .CssClass = "AdminRateFAREntry"
                        .HorizontalAlign = HorizontalAlign.Left
                        .Text = dsDetail.Tables(0).Rows(i).Item("Unit_Name") & " (" & dsDetail.Tables(0).Rows(i).Item("Qty_per_Unit") & ") &nbsp;"
                    End With

                    row.Cells.Add(cell)

                    'creates calendar labels, images, and hidden fields
                    cell = New TableCell

                    With cell
                        .HorizontalAlign = HorizontalAlign.Left
                        .CssClass = "AdminRateFAREntry"
                        .ID = "tdFromDt_" & CStr(k) ' dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id")
                        Dim Label As New Label
                        With Label
                            .ID = "lblFrom_" & CStr(k) ' dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id")
                            .CssClass = "Calendar"
                            .BorderStyle = BorderStyle.None
                            .Text = dsDetail.Tables(0).Rows(i).Item("Required_Dt")
                        End With
                        .Controls.Add(Label)
                        Label = New Label
                        Label.Text = " "
                        .Controls.Add(Label)
                        Dim hid As New HiddenField
                        With hid
                            .ID = "hidFrom_" & CStr(k) ' dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id")
                        End With
                        .Controls.Add(hid)
                        img = New WebControls.ImageButton
                        With img
                            .ImageUrl = "..\images\calendar.gif"
                            .ID = "imgFrom_" & k
                            .ToolTip = "Click to Edit"
                            .CssClass = "Calendar"
                            .OnClientClick = "return swap('from_" & CStr(k) & "');" ' dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id") & "');"
                        End With
                        .Controls.Add(img)
                    End With

                    row.Cells.Add(cell)

                    'creates calendar labels
                    cell = New TableCell

                    With cell
                        .HorizontalAlign = HorizontalAlign.Left
                        .CssClass = "AdminRateFAREntry"
                        .Width = Unit.Pixel(100)
                        .ID = "tdToDt_" & CStr(k) ' dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id")
                        Dim Label As New Label '
                        With Label
                            .ID = "lblTo_" & CStr(k) ' dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id")
                            .CssClass = "Calendar"
                            .BorderStyle = BorderStyle.None
                            .Text = dsDetail.Tables(0).Rows(i).Item("End_Dt")
                        End With
                        .Controls.Add(Label)
                        Label = New Label
                        Label.Text = " "
                        .Controls.Add(Label)
                        img = New WebControls.ImageButton
                        With img
                            .ImageUrl = "..\images\calendar.gif"
                            .ID = "imgTo_" & k
                            .ToolTip = "Click to Edit"
                            .CssClass = "Calendar"
                            .OnClientClick = "return swap('to_" & CStr(k) & "');" 'dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id") & "');"
                        End With
                        .Controls.Add(img)
                        Dim hid As New HiddenField
                        With hid
                            .ID = "hidTo_" & CStr(k) ' dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id")
                        End With
                        .Controls.Add(hid)
                    End With

                    row.Cells.Add(cell)

                    'blank space
                    cell = New TableCell
                    cell.Text = ""
                    row.Cells.Add(cell)

                    'creates txtQty
                    cell = New TableCell
                    With cell
                        Dim txt As New TextBox
                        With txt
                            .Text = dsDetail.Tables(0).Rows(i).Item("Qty")
                            .ID = "txtQty_" & CStr(k) ' dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id")
                            .Width = Unit.Pixel(25)
                            .Font.Size = FontUnit.Point(8)
                            .Font.Name = "Verdana"
                        End With
                        .Controls.Add(txt)
                        Dim hidID As New HiddenField
                        With hidID
                            .ID = "hidID_" & CStr(k) ' dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id")
                            .Value = dsDetail.Tables(0).Rows(i).Item("Order_Dtl_Id")
                        End With
                        .Controls.Add(hidID)
                    End With
                    row.Cells.Add(cell)
                    Me.tblAdminTable.Rows.Add(row)

                    'addition of horizontal rule
                    row = New TableRow
                    cell = New TableCell
                    cell.ColumnSpan = 7
                    Dim hr As New HtmlGenericControl
                    hr.TagName = "hr"
                    hr.Attributes.Add("size", "1")
                    cell.Controls.Add(hr)
                    row.Cells.Add(cell)
                    Me.tblAdminTable.Rows.Add(row)
                Next
            End If

-----------------------------------------------------------------------------------------------------------------

Below is javascript involved (with code I'm looking at in bold)

var theIndex;
function swap(loc_idx)
{

theIndex = loc_idx;
    var ary = loc_idx.split("_")
    var loc = String(ary[0]); // defines the column location ("from" or "to" column)
    var idx = String(ary[1]); // defines the row index of the column for the swap
    //var idx = loc_idx; // defines the row index of the column for the swap
    var cal = document.getElementById("wdcDate"); //document.getElementById("<%= wdcDate.ClientID %>"); //$find("<%= wdcDate.ClientID %>"); //document.getElementById("wdcDate");
    var oCal = $find("<%= wdcDate.ClientID %>"); // igdrp_getComboById("wdcDate");
    
//debugger;
    var hidSwapLoc = document.getElementById("hidSwapLoc");
       if (loc == "from")
    {
        hidSwapLoc.value = "from_" + idx;
        //get current date in textbox to display in calendar
        var txtID = "lblFrom_" + idx;
        var txt = document.getElementById(txtID);       
        var txtVal = txt.innerText;
        var fromDt = new Date(txtVal);
        var cellId = "tdFromDt_" + idx;
        var cell = document.getElementById(cellId);
        //cell.value = "";
        cell.appendChild(cal);
        oCal.set_value(fromDt);
        oCal.setCalendarOpened(true,true); //showCalendar();
    }
    else
    {
        if (loc == "to")
        {
            hidSwapLoc.value = "to_" + idx;
            var txtID = "lblTo_" + idx;
            var txt = document.getElementById(txtID);
            var txtVal = txt.innerText;
            var toDt = new Date(txtVal);
            var cellId = "tdToDt_" + idx;
            var cell = document.getElementById(cellId);
//            cell.value = "";
            cell.appendChild(cal);
            oCal.set_value(toDt);
            oCal.setCalendarOpened(true,true); //showCalendar();
        }
    }
      
    return false;
}

----------------------------------------------------------------------------------------------

Any thoughts on what i need to do to get this to work in with webdatechooser would be great

Thanks in advance

Steve Z

  • 29417
    Offline posted

    Hello Steve,

     

    I’m just following up to see if you’ve been able to resolve your issue. If you have any questions or concerns or if you need further assistance please let me know.

     

    Best Regards,

    Maya Kirova

    Developer Support Engineer

    Infragistics, Inc.

    http://ko.infragistics.com/support

     

  • 29417
    Offline posted

    Hello Steve,

     

    Thank you for posting in our forum.

    I’ve tested the described scenario with a WebDatePicker control and it seems to work as expected.

    I’ve attached a sample for your reference. When you click on the date chooser images the WebDataPicker is appended to the cell as expected and opened.

     What exactly is the issue you’ve come across? Is in your case the element that you get by id null(  var cal = document.getElementById("wdcDate");)?

    If the controls is nested in some  other container controls it’s possible that “wcdDate” is not exactly its client id. If that’s the case then this call would return null.

    However I see you’ve tried other approaches as well and generally this one: document.getElementById("<%= wdcDate.ClientID %>");

    Should work as expected.

     

    Please refer to the attached sample and let me know if I’m missing anything from your scenario.

     

    Best Regards,

    Maya Kirova

    Developer Support Engineer

    Infragistics, Inc.

    http://ko.infragistics.com/support

     

    WebDatePicker_Move.zip