Sunday, March 11, 2012

Nested ReorderList - Javascript Exception

Any chance someone from Microsoft could look at this?
I can't believe there's no activity on this...this has to be a known issue. Would someone from Microsoft please chime in?

Here is the code I am struggling with:

1<asp:SqlDataSource2 ID="sqlCategories"3 runat="server"4 ConnectionString="<%$ ConnectionStrings:ConnDB%>"5 ProviderName="System.Data.SqlClient"6 SelectCommand="pub_SelectCategories" SelectCommandType="StoredProcedure">7 <SelectParameters>8 <asp:Parameter Name="ApplicationID" />9 </SelectParameters>10</asp:SqlDataSource>11<asp:GridView12 ID="gvCategories"13 runat="server"14 DataSourceID="sqlCategories"15 OnRowDataBound="gvCategories_OnRowDataBound"16 AutoGenerateColumns="false">17 <Columns>18 <asp:TemplateField>19 <ItemTemplate>20 <h3><%# Eval("Name")%></h3><asp:HiddenField ID="hiddenCategoryID" runat="server" Value='<%# Eval("ID")%>' />21 <asp:SqlDataSource22 ID="sqlLinks"23 runat="server"24 ConnectionString="<%$ ConnectionStrings:ConnDB%>"25 ProviderName="System.Data.SqlClient"26 SelectCommand="pub_SelectLinks" SelectCommandType="StoredProcedure"27 UpdateCommand="pub_UpdateLink" UpdateCommandType="StoredProcedure"28 DeleteCommand="pub_DeleteLink" DeleteCommandType="StoredProcedure"29 InsertCommand="pub_InsertLink" InsertCommandType="StoredProcedure">30 <SelectParameters>31 <asp:Parameter Name="ApplicationID" />32 <asp:Parameter Name="CategoryID" />33 </SelectParameters>34 <UpdateParameters>35 <asp:Parameter Name="ApplicationID" />36 <asp:Parameter Name="ID" />37 <asp:Parameter Name="CategoryID" />38 <asp:Parameter Name="Name" Type="String" />39 <asp:Parameter Name="Url" Type="string" />40 <asp:Parameter Name="Title" Type="String" />41 <asp:Parameter Name="DisplayOrder" Type="Int32" />42 </UpdateParameters>43 <DeleteParameters>44 <asp:Parameter Name="ApplicationID" />45 <asp:Parameter Name="ID" />46 </DeleteParameters>47 <InsertParameters>48 <asp:Parameter Name="ApplicationID" />49 <asp:Parameter Name="CategoryID" />50 <asp:Parameter Name="Name" Type="String" />51 <asp:Parameter Name="Title" Type="String" />52 <asp:Parameter Name="Url" Type="String" />53 </InsertParameters>54 </asp:SqlDataSource>55 <ajaxToolkit:ReorderList56 ID="ReorderLinks"57 runat="server"58 DataSourceID="sqlLinks"59 DataKeyField="ID"60 SortOrderField="DisplayOrder"61 AllowReorder="true"62 PostBackOnReorder="true"63 DragHandleAlignment="Left"64 CssClass="ajaxReorderList"65 ItemInsertLocation="end"66 OnItemCommand="ReorderLinks_OnItemCommand">67 <ItemTemplate>68 <div class="itemArea">69 <div class="controls">70 <asp:LinkButton ID="lnkEdit" runat="server" CommandName="Edit" Text="Edit" /><br />71 <asp:LinkButton ID="lnkDelete" runat="server" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you sure you want to delete this category?');" />72 </div>73<%# Eval("Name")%> (<%# Eval("Title")%>)<br />74<%# Eval("Url")%>75 </div>76 </ItemTemplate>77 <EditItemTemplate>78 <div class="editItemArea">79 <div class="controls">80 <asp:LinkButton ID="lnkCancel" runat="server" CommandName="Cancel" Text="Cancel" /><br />81 <asp:LinkButton ID="lnkUpdate" runat="server" CommandName="Update" Text="Update" />82 </div>83 <div>84 <asp:Label ID="lblName" runat="server" AssociatedControlID="txtName">Name:</asp:Label>85 <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name")%>' />86 <asp:Label ID="lblTitle" runat="server" AssociatedControlID="txtTitle">Hover Text:</asp:Label>87 <asp:TextBox ID="txtTitle" runat="server" Text='<%# Bind("Title")%>' />88 </div>89 <div>90 <asp:Label ID="lblUrl" runat="server" AssociatedControlID="txtUrl">Url:</asp:Label>91 <asp:TextBox ID="txtUrl" runat="server" Text='<%# Bind("Url")%>' />92 </div>93 <asp:HiddenField ID="hiddenDisplayOrder" runat="server" Value='<%# Bind("DisplayOrder")%>' />94 </div>95 </EditItemTemplate>96 <ReorderTemplate>97 <div class="reorderArea"></div>98 </ReorderTemplate>99 <DragHandleTemplate>100 <div class="dragHandle"></div>101 </DragHandleTemplate>102 <InsertItemTemplate>103 <asp:Panel ID="Panel1" runat="server" DefaultButton="btnAdd" CssClass="addItemArea">104 <div class="controls">105 <asp:Button ID="btnAdd" runat="server" CommandName="Insert" Text="Add" />106 </div>107 <div>108 <asp:Label ID="lblName" runat="server" AssociatedControlID="txtName">Name:</asp:Label>109 <asp:TextBox ID="txtName" runat="server" Text='<%# Bind("Name")%>' />110 <asp:Label ID="lblTitle" runat="server" AssociatedControlID="txtTitle">Hover Text:</asp:Label>111 <asp:TextBox ID="txtTitle" runat="server" Text='<%# Bind("Title")%>' />112 </div>113 <div>114 <asp:Label ID="lblUrl" runat="server" AssociatedControlID="txtUrl">Url:</asp:Label>115 <asp:TextBox ID="txtUrl" runat="server" Text='<%# Bind("Url")%>' />116 </div>117 </asp:Panel>118 </InsertItemTemplate>119 </ajaxToolkit:ReorderList>120 </ItemTemplate>121 </asp:TemplateField>122 </Columns>123</asp:GridView>

1protected void ReorderLinks_OnItemCommand(object sender, AjaxControlToolkit.ReorderListCommandEventArgs e)2 {3 AjaxControlToolkit.ReorderList ReorderLinks = (AjaxControlToolkit.ReorderList)sender;4 SqlDataSource sqlLinks = (SqlDataSource)ReorderLinks.Parent.FindControl("sqlLinks");5 HiddenField hiddenCategoryID = (HiddenField)ReorderLinks.Parent.FindControl("hiddenCategoryID");67if (e.CommandName =="Update")8 {9 sqlLinks.UpdateParameters["ApplicationID"].DefaultValue = _ApplicationID.ToString();10 sqlLinks.UpdateParameters["CategoryID"].DefaultValue = hiddenCategoryID.Value;11 }12else if (e.CommandName =="Delete")13 {14 sqlLinks.DeleteParameters["ApplicationID"].DefaultValue = _ApplicationID.ToString();15 }16else if (e.CommandName =="Insert")17 {18 sqlLinks.InsertParameters["ApplicationID"].DefaultValue = _ApplicationID.ToString();19 sqlLinks.InsertParameters["CategoryID"].DefaultValue = hiddenCategoryID.Value;20 }21 }2223protected void ReorderLinks_OnItemReorder(object sender, AjaxControlToolkit.ReorderListItemReorderEventArgs e)24 {25 AjaxControlToolkit.ReorderList ReorderLinks = (AjaxControlToolkit.ReorderList)sender;26 SqlDataSource sqlLinks = (SqlDataSource)ReorderLinks.Parent.FindControl("sqlLinks");27 HiddenField hiddenCategoryID = (HiddenField)ReorderLinks.Parent.FindControl("hiddenCategoryID");2829 sqlLinks.UpdateParameters["ApplicationID"].DefaultValue = _ApplicationID.ToString();30 sqlLinks.UpdateParameters["CategoryID"].DefaultValue = hiddenCategoryID.Value;3132 sqlCategories.DataBind();33 }

Try to fix this in the Toolkit. In ReorderList.cs, line 637 try changing:

_dropWatcherExtender.BehaviorID =

this.ID +"_dItemEx";

to

_dropWatcherExtender.BehaviorID =

this.UniqueID +"_dItemEx";

Shawn,

Thanks a ton for taking the time to look at this--That fixed it! Should I submit a bug report on Codeplex about this?


Nah, I'll just check it in after I run some tests, etc.
Sweet! Thanks again, you rock!

No comments:

Post a Comment