ASP.NET2.0中用户控件中Datalist的ItemTemplate控件的问题,急!
问题是这样的,我创建了一个用户控件如下:
<asp:Panel ID="DailyPickPanel" runat="server" Width="100%">
<table width="100%" cellpadding="5" cellspacing="0">
<tr class="rheader">
<td align="left" style="height:25" class="rheadercol">Pick Of The Day</td>
</tr>
<tr class="rbody">
<td align="left" style="height:25" class="rbodycol">
<asp:DataList ID="DtDailyPicker" runat="server" Width="100%" DataKeyField="PKId" CellPadding="0" CellSpacing="0" BorderStyle="none" DataSourceID="DailyPickerSource" RepeatLayout="Table" RepeatColumns="2" RepeatDirection="Horizontal">
<ItemStyle Width="50%" />
<ItemTemplate>
<table width="100%" border="0">
<tr>
<td rowspan="2" align="center" style="width:80">
<asp:Image ID="BookImage" runat="server" EnableViewState="false" ImageUrl='<%# "~/images/books/"+Eval("ImageFileSpec") %>' />
</td>
<td>
<asp:HyperLink ID="BookLink" runat="server" EnableViewState="false" NavigateUrl='<%#"~/Books.aspx?id="+Eval("PKId")%>'>
<%#Eval("Title") %>
</asp:HyperLink>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblBookDes" EnableViewState="false" runat="server" Text='<%#Eval("Description") %>'></asp:Label>
<br /><br />
Our Price:
<asp:Label ID="lblPrice" runat="server" EnableViewState="false" Text='<%#Eval("UnitPrice","{0:C}") %>'></asp:Label>
<br /><br />
<asp:Button ID="BtnCart" runat="server" EnableViewState="true" Text="Add to Cart" CommandName="Add" CommandArgument='<%#Eval("PKId")+"|"+Eval("Description")+"|"+Eval("UnitPrice") %>' OnClick="BtnCart_Click"/>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
<asp:SqlDataSource ID="DailyPickerSource" runat="server" ConnectionString="<%$ ConnectionStrings:Duwamish7ConnectionString %>"
SelectCommand="GetDailyPickBooksByCategoryId" SelectCommandType="StoredProcedure">
<SelectParameters>
<asp:QueryStringParameter DefaultValue="1" Name="CategoryId" QueryStringField="id"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
</asp:Panel>
在BtnCart_Click中,通过BtnCart的CommandArgument来获取每一行的ID,编译通过,运行时按这个按钮就报错如下:
Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.
但是如果我直接放在页面里面就没什么问题,是不是这种方式在用户控件里面不行?有什么其他方法达到相同的效果呢?