This is a weird issue. I have a List view with 2 Link buttons. "Edit" and "Delete" Iam able to attach an event handler for the first linkbutton(Update). Code in the event handler executed fine. But If I try to attach a event handler for the second link button(Delete) , I get an error.
My Item Template Looks like this.
<ItemTemplate>
<tr>
<td>
<asp:Label ID="MessageLabel" runat="server" Text='<%# Eval("Item") %>' />
</td>
<td>
<asp:Label ID="URLLabel" runat="server" Text='<%# Eval("URL") %>' />
</td>
<td>
<asp:LinkButton ID="EditLinkButton" runat="server" OnClick="EditLinkButtonClicked"
CommandArgument='<%# Eval("ItemID") %>'> Edit</asp:LinkButton>
</td>
<td>
<asp:LinkButton ID="DeleteLinkButton" runat="server" OnClick="DeleteLinkButtonClicked"
CommandArgument='<%# Eval("ItemID") %>'>Delete</asp:LinkButton>
</td>
</tr>
</ItemTemplate>
The Event handler declared in the codebehind file are
public void EditLinkButtonClicked(object sender, EventArgs e) { ----- }
public void DeleteLinkButtonClicked(object sender, EventArgs e) { ----- } [Exactly same]
First Item works absolutely fine. But If I attach the second handler, I get the following error
Am I missing some thing ? Note - There is no error if I try to attach t开发者_如何学Che 1st event handler to the second link button.[ie EditLinkButtonClicked to DeleteLinkButtonClicked ] Issue occurs only when I try to attach DeleteLinkButtonClicked to DeleteLinkButton
Any help? Thanks in Advance
Try to disable EnableEventValidation for the Page directive and check it.
<%@ Page EnableEventValidation="false" %>
If it help then you should to know that:
This feature reduces the risk of unauthorized or malicious postback requests and callbacks. It is strongly recommended that you do not disable event validation.
regarding to http://msdn.microsoft.com/en-us/library/system.web.ui.page.enableeventvalidation.aspx and try to avoid this in the way that was suggested here.
It'd be three things:
You need to clean, rebuild solution, and reset IIS or close ASP.NET development server (maybe some cache is preventing you to execute the most recent version of the code-behind class).
Typo. Double-check that...!
Event handler hasn't the right signature.
Anyway, why don't you use the "Command" event?
You can do OnCommand="Item_Command" and the event handler will have CommandEventArgs which provides you the CommandName and CommandArgument, so you can switch the command name and invoke the logic for editing or deleting respectively.
Read more here:
- http://msdn.microsoft.com/es-es/library/system.web.ui.webcontrols.commandeventargs_members.aspx
The same problem occurs in my code. I resolved by using CausesValidation="false"
<asp:LinkButton ID="YourID" runat="server" **CausesValidation="false"** OnClick="Category_btn_Click1" />
精彩评论