Welcome Guest Search | Active Topics | Sign In | Register

Postback error in grid with 3 custom and 3 masked edit dynamically created columns Options
infoland
Posted: Friday, November 18, 2011 11:06:42 AM
Rank: Member
Groups: Member

Joined: 11/15/2011
Posts: 24
Hi.
Under certain conditions, doing a postback of a grid causes the following error:

"An error has occurred because a control with id 'Grid$edit$ctl05' could not be located or a different control is assigned to the same ID after postback. If the ID is not assigned, explicitly set the ID property of controls that raise postback events to avoid this error."

After many hours struggling around this annoying problem, I finally isolated the conditions into a small project.
Here's my source code:

Code: HTML/ASPX
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Test.aspx.vb" Inherits="TestEOWebGrid.Test" %>
<%@ Register assembly="EO.Web" namespace="EO.Web" tagprefix="eo" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>TEST EO WEB GRID</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <script type="text/javascript" language="javascript">
            function customColumn_getText(column, item, cellValue) {
                return '<span title="Cell code: ' + cellValue + '">' + cellValue + '</span>';
            }
            function customColumn_beginEdit(cell) {
            }
        </script>

        <eo:Grid ID="Grid" runat="server" BorderColor="#C7D1DF" BorderWidth="1px" 
            ColumnHeaderAscImage="00050303" ColumnHeaderDescImage="00050304" 
            ColumnHeaderDividerImage="00050302" Font-Bold="False"
            Font-Italic="False" Font-Names="Tahoma" Font-Overline="False" Font-Size="8pt" 
            Font-Strikeout="False" Font-Underline="False" GridLineColor="199, 209, 223" 
            GridLines="Both" Height="200px" ItemHeight="19" Width="790px" 
            FullRowMode="False">
            <ItemStyles>
                <eo:GridItemStyleSet>
                    <ItemStyle CssText="background-color: white" />
                    <ItemHoverStyle CssText="background-image: url(00050206); background-repeat: repeat-x" />
                    <SelectedStyle CssText="background-image: url(00050207); background-repeat: repeat-x" />
                    <CellStyle CssText="padding-left:8px;padding-top:2px; color:#336699;white-space:nowrap;" />
                </eo:GridItemStyleSet>
            </ItemStyles>
            <Columns>
                <eo:RowNumberColumn></eo:RowNumberColumn>
            </Columns>
            <ColumnHeaderStyle CssText="background-image:url('00050301');padding-left:8px;padding-top:2px;font-weight: bold;color:white;" />
            <ColumnTemplates>
                <eo:MaskedEditColumn>
                    <MaskedEdit ControlSkinID="None">
                        <eo:MaskedEditSegment MaxValue="99" SegmentType="Number" />
                    </MaskedEdit>
                </eo:MaskedEditColumn>
            </ColumnTemplates>
            <FooterStyle CssText="padding-bottom:4px;padding-left:4px;padding-right:4px;padding-top:4px;" />
        </eo:Grid>
    </div>
    <p>
	     <asp:Panel id="panChanges" Width="400px" runat="server" Visible="False">Change Summary:<br/></asp:Panel>
	    <asp:Button id="Button1" Text="Post Back!" Runat="server" OnClick="Button1_Click"></asp:Button>
    </p>
    </form>
</body>
</html>


Code: Visual Basic.NET
Imports EO.Web
Imports System.Data

Public Class Test
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(sender As Object, e As System.EventArgs)
        panChanges.Visible = True

        Dim s As String = String.Empty
        If Grid.ChangedItems.Length = 0 Then
            s += "No item has changed."
        Else
            Dim item As EO.Web.GridItem
            For Each item In Grid.ChangedItems
                Dim cell As EO.Web.GridCell
                For Each cell In item.Cells
                    If cell.Modified Then
                        Dim [text] As String = String.Format("Cell Changed: Key = {0}, Field = {1}, New Value = {2}", item.Key, cell.Column.DataField, cell.Value)

                        s += "<br />"
                        s += [text]
                    End If
                Next cell
            Next item
        End If

        Dim info As New Literal()
        info.Text = s
        panChanges.Controls.Add(info)
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        BuildGridLayout()
        If Not IsPostBack Then
            With Grid
                .DataSource = BuildGridDataSource()
                .DataBind()
            End With
            Grid.Height = Grid.ItemHeight * Grid.Items.Count + Grid.ColumnHeaderHeight
        End If
    End Sub

    Private Sub BuildGridLayout()
        With Grid
            .Columns.Clear()
            For i = 1 To 3
                Dim customColumn As New CustomColumn With { _
                        .DataField = "Code" & i, _
                        .HeaderText = "Code" & i, _
                        .Name = "Code" & i, _
                        .ClientSideGetText = "customColumn_getText", _
                        .ClientSideBeginEdit = "customColumn_beginEdit", _
                        .EditorTemplate = New EmptyTemplate
                    }
                .Columns.Add(customColumn)
            Next
            For i = 1 To 3
                Dim maskedColumn As New MaskedEditColumn With { _
                        .DataField = "Value" & i, _
                        .HeaderText = "Value" & i, _
                        .Width = 50
                    }
                .Columns.Add(maskedColumn)
            Next
        End With
    End Sub

    Private Function BuildGridDataSource() As DataTable
        Dim dt As New DataTable
        dt.Columns.Add("Text", GetType(String))
        For i = 1 To 10
            dt.Columns.Add("Value" & i, GetType(Integer))
            dt.Columns.Add("Code" & i, GetType(Integer))
        Next
        For r = 0 To 5
            Dim dr = dt.NewRow()
            dr("Text") = "Text " & r
            For i = 1 To 10
                dr("Value" & i) = r * 10 + i
                dr("Code" & i) = (r + i) Mod 5
            Next
            dt.Rows.Add(dr)
        Next
        Return dt
    End Function
End Class

Public Class EmptyTemplate
    Implements ITemplate

    Public Sub InstantiateIn(container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
        container.Controls.Add(New LiteralControl(""))
    End Sub
End Class


The error occurs if there are exactly 3 MaskedEditColumns and 3 CustomColumns.
In addition, it does not occur if the columns are defined at design time.

Please, I need some advice to get out from this impasse.
Thanks
eo_support
Posted: Friday, November 18, 2011 1:07:49 PM
Rank: Administration
Groups: Administration

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

Thank you very much for the sample code. The root of the probelm is still that CustomColumn could not restore ItemTemplate through view state. So when the view states go down to the client it has 6 "editors" (3 from CustomColumn and 3 from MaskedEditColumn), but when it comes back it could only restore 3 with the wrong order (the first one was CustomColumn's "editor" but it's now MaskedEditColumn's "editor"). Unfortunately we have not been able to find a workaround for this. So we will have to change our code in order to fix the problem. We will fix it as soon as possible and should be able to provide you a new build early next week.

Thanks!
infoland
Posted: Friday, November 18, 2011 1:21:04 PM
Rank: Member
Groups: Member

Joined: 11/15/2011
Posts: 24
Ok, that was a bit annoying but I can almost easily overcome it using standard TextBoxColumn in place of MaskedEditColumn and a bunch of Javascript code to validate input ;-).

Thanks for your support.
eo_support
Posted: Friday, November 18, 2011 1:24:16 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,194
Ah. Thank you very much for sharing. Haven't thought about that. : )
Kristin Schreiter
Posted: Friday, December 2, 2011 5:40:56 AM
Rank: Newbie
Groups: Member

Joined: 9/5/2011
Posts: 2
Hi,

I have the same issue when I use a mix of dynamically created CustomColumns and DateTimeColumns in one grid. It seems to work when the first column is the DateTimeColumn and the second the CustomColumn, but vice versa I get the error message that the control with id 'Grid1$edit$ctl02' could not be located after postback, where 'Grid1$edit$ctl02' is the id of the DatePicker. Have you already managed to fix the problem or could you give me some advice?

Thanks
eo_support
Posted: Friday, December 2, 2011 4:37:50 PM
Rank: Administration
Groups: Administration

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

We have posted a new build that addressed this issue. Please see your private message for the download location.

Thanks!


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.