好的,我知道這個問題已經被問了很多,我在網上發現了很多關於此的信息。不幸的是,它似乎沒有一個真正爲我工作。從YouTube發射回發
基本上,我有一些JavaScript響應用戶事件而運行。 JavaScript獲得了一些信息(一個int),然後我想將它返回給服務器。
第一種方法是使用Page.ClientScript.GetPostBackEventReference
獲得__DoPostBack()
的有效呼叫,如here所述。
我用這個方法觸發一個按鈕的回發。這似乎是工作,除了我得到的錯誤:
Invalid postback or callback argument. Event validation is enabled using 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.
接下來,我試圖用一個HiddenField的ValueChanged
事件處理程序。我寫了我的處理程序,但更改隱藏字段的值不會觸發事件。某種形式的回傳仍然需要以某種方式觸發。
我真的不明白爲什麼我會遇到這麼多麻煩。有沒有更直接的方式來做我所需要的?