[英]asp:LinkButton vs asp:Button. Invalid postback or callback argument
我最近對某些CSS樣式使用了asp:LinkButton而不是asp:Button。
<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" />
我不知道當我單擊btnRegister_Click
出現錯誤
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.
但是Button1_Click
上沒有錯誤。
我知道禁用EnableEventValidation="false"
存在一些安全問題。
編輯:加載和單擊上沒有代碼,我與我的設計人員代碼混淆:))。
我意識到有多種形式,沒有runat=server
但有method=postback
屬性。 我清除了多余的表格並解決了問題。
為什么這樣的asp:linkbutton
行為都沒有asp:button
任何想法?
編輯2:請不要告訴我將EnableEventValidation
更改為false,我不希望存在頁面安全性的風險。 另外,我補充
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
在web.config中,並沒有工作。
如果在頁面加載中綁定了gridview或datalist或repeater,則必須這樣做:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//all code in page_load
}
}
您已經可以按照錯誤消息的建議進行操作,並使用ClientScriptManager.RegisterForEventValidation方法來注冊回發或回調數據以進行驗證。
或者,您可以將頁面的EnableEventValidation設置為false。
檢查與AutoEventWireup="true"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.