我在vb一侧有一个datalist和一个binddata Sub,可以在页面加载时工作,我可以看到我的所有数据,但是当我点击编辑它时会出现这个错误: -
无效的回发或回调参数。使用配置或<%@ Page EnableEventValidation =" true"启用事件验证。 %GT;在一个页面中。出于安全考虑,此功能可验证回发或回调事件的参数是否来自最初呈现它们的服务器控件。如果数据有效且符合预期,请使用ClientScriptManager.RegisterForEventValidation方法注册回发或回调数据以进行验证。
这是我的vb代码: -
Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
BindData()
End Sub
Protected Sub BindData()
Dim cn As SqlConnection = New SqlConnection()
Dim cmd As SqlCommand = New SqlCommand()
cn.ConnectionString = ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString
cmd.Connection = cn
cmd.CommandText = "SELECT DISTINCT Users.User_ID, Users.FirstName, Users.LastName, Users.Password, Users.Email, Users.ContactNum, Users.Address, Users.County, Users.Gender, Users.Datejoined, Users.Dateleft, Users.Subscription_ID, Subscriptions.Subscription_type FROM Users INNER JOIN Subscriptions ON Users.Subscription_ID = Subscriptions.Subscription_ID WHERE (Users.Dateleft IS NULL)"
cn.Open()
Dim ds As SqlDataReader
ds = cmd.ExecuteReader()
MyDataList.DataSource = ds
MyDataList.DataBind()
cn.Close()
End Sub
Sub myDataList_EditCommand(sender As Object, e As DataListCommandEventArgs) Handles MyDataList.EditCommand
BindData()
MyDataList.EditItemIndex = e.Item.ItemIndex
End Sub
这是我的asp.net: -
<asp:DataList ID="MyDataList"
runat="server"
RepeatColumns="2" CellSpacing="-1" Font-Bold="False" Font-Italic="False"
Font-Names="Arial" Font-Overline="False" Font-Size="Medium"
Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
ShowFooter="False" ShowHeader="False"
onItemDataBound="myDataList_ItemDataBound"
onEditCommand="myDataList_EditCommand"
onCancelCommand="myDataList_CancelCommand"
onUpdateCommand="myDataList_UpdateCommand"
onDeleteCommand="myDataList_DeleteCommand"
RepeatDirection="Horizontal">
<ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
VerticalAlign="Middle" />
<ItemTemplate>
<br />
<div style="padding:15,15,15,15;font-size:10pt;font-family:Verdana">
<table class="style1">
<tr>
<td class="style2">
User ID</td>
<td>
<asp:Label ID="lblID" runat="server" Text='<%# Eval("User_ID") %>' />
</td>
</tr>
<tr>
<td class="style2">
Details</td>
<td>
<i><b>
<asp:Label ID="lblFName" runat="server" Text='<%# Eval("FirstName") %>' />
<asp:Label ID="lblLName" runat="server" Text='<%# Eval("LastName") %>' />
</i></b>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="Address" runat="server" Text='<%# Eval("Address") %>' />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblCounty" runat="server" Text='<%# Eval("County") %>' />
</td>
</tr>
<tr>
<td class="style2">
Contact Details</td>
<td>
<asp:Label ID="lblEmail" runat="server" Text='<%# Eval("Email") %>' />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblNum" runat="server" Text='<%# Eval("ContactNum") %>' />
</td>
</tr>
<tr>
<td class="style2">
Package ID</td>
<td>
<asp:Label ID="lblSub" runat="server" Text='<%# Eval("Subscription_ID") %>' />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblDes" runat="server" Text='<%# Eval("Subscription_type") %>' />
</td>
</tr>
<tr>
<td class="align-center" colspan="2">
<asp:Button ID="btnEdit" runat="server" CommandName="Edit" Text="Edit" />
<asp:Button ID="btnDelete" runat="server" CommandName="Delete" Text="Delete" />
</td>
</tr>
</table></div>
<br />
</ItemTemplate>
<EditItemTemplate>
<table class="style1">
<tr>
<td class="style2">
User ID</td>
<td>
<asp:Label ID="lblID" runat="server" Text='<%# Eval("User_ID") %>' />
</td>
</tr>
<tr>
<td class="style2">
Details</td>
<td>
<asp:TextBox ID="txtFName" runat="server" text='<%#Container.DataItem("FirstName")%>'></asp:TextBox>
<asp:TextBox ID="txtLName" runat="server" text='<%#Container.DataItem("LastName")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style3">
</td>
<td class="style4">
<asp:TextBox ID="lblAdd" runat="server"
text='<%#Container.DataItem("Address")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:TextBox ID="lblCounty" runat="server"
text='<%#Container.DataItem("County")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Contact Details</td>
<td>
<asp:TextBox ID="lblEmail" runat="server"
text='<%#Container.DataItem("Email")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:TextBox ID="lblNum" runat="server"
text='<%#Container.DataItem("ContactNum")%>'></asp:TextBox>
</td>
</tr>
<tr>
<td class="style2">
Package ID</td>
<td>
<asp:Label ID="lblSub" runat="server" Text='<%# Eval("Subscription_ID") %>' />
</td>
</tr>
<tr>
<td class="style2">
</td>
<td>
<asp:Label ID="lblDes" runat="server" Text='<%# Eval("Subscription_type") %>' />
</td>
</tr>
<tr>
<td class="align-center" colspan="2">
<asp:LinkButton ID="lnkUpdate" runat="server" CommandName="Update">Update</asp:LinkButton>
<asp:LinkButton ID="lnkCancel" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
</td>
</tr>
</table>
</EditItemTemplate><SelectedItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False"
Font-Strikeout="False" Font-Underline="False" HorizontalAlign="Center"
VerticalAlign="Middle" />
我已将Page EnableEventValidation =&#34; false&#34;但这只是什么都没做,我不告诉错误,但没有任何反应。
请帮帮我。
答案 0 :(得分:0)
尝试更改以下代码:
Sub myDataList_EditCommand(sender As Object,e As DataListCommandEventArgs)处理MyDataList.EditCommand BindData() MyDataList.EditItemIndex = e.Item.ItemIndex 结束子
到这个
Sub myDataList_EditCommand(sender As Object,e As DataListCommandEventArgs)处理MyDataList.EditCommand MyDataList.EditItemIndex = e.Item.ItemIndex MyDataList.DataBind() 结束子