简体   繁体   中英

asp:LinkButton vs asp:Button. Invalid postback or callback argument

I recently use asp:LinkButton instead of asp:Button for some CSS styles.

<asp:LinkButton ID="btnRegister" CssClass="btn btn-primary btn-lg btnSend" runat="server" OnClick="btnRegister_Click">Submit</asp:LinkButton>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />

I wonder that when I click on btnRegister_Click I get error that

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.

but there is no error on Button1_Click .

I know that disabling EnableEventValidation="false" has some security issues.

  1. What's different between asp:LinkButton and asp:Button on postback event?
  2. what is best and secure solution in this case?

Edit: There is no code on load and click, I was confused with my designer coding :)).
I realize that there are multi forms without runat=server but with method=postback attributes. I clear that extra forms and problem resolved.

any Idea of why asp:linkbutton behavior like this neither asp:button ?

Edit 2: please don't tell me to change EnableEventValidation to false, I don't want the risk of page security. also, I add

<appSettings>
   <add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>

in web.config and didn't work.

if you bind gridview or datalist or repeater in page load, must do it:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        //all code in page_load
        }
     }

already You could do as the error message suggests and use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation.

Or you could just set EnableEventValidation for the page to false.

检查与AutoEventWireup="true"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM