Welcome to MSDN Blogs Sign in | Join | Help

Why do I get "Invalid postback or callback argument" Errors?

Introduction:

 

This is the first post of mine so thought of starting with a simple but tricky issue which I came across in few support incidents I have handled. I had a scenario where one of my customers was getting an error message like -

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.

 

Many of us get this error message often, either in the event viewer or on the page itself. But what does it signify? When does it come up? What we can do to eliminate this exception due to coding mistakes?

 

What does it signify?

 

In ASP.NET 2.0 we have added a feature called event validation. Event validation checks the incoming POST request to ensure that the event causing the Postback / callback is valid and the event which triggered the Postback /callback is expected by the Runtime. If the runtime finds a Postback / callback by an event which is not registered for validation, it throws an exception.  This has been added in ASP.NET 2.0 explicitly to prevent the attack to the application by spoofing a Postback. Event validation can help prevent injection attacks from malicious users who are trying to POST data by an event which does not come up from the controls registered to the page.

You can enable or disable this feature by simply setting up Property EnableEventValidation = true in the web.config or on the page level. By default it is enabled. You can find more information about this property in the MSDN link. 

So this is about all the “good” which event validation signifies. Agreed that this is a very good security feature which helps preventing script injection attacks but if it is coming during the normal execution of an application, the exception is not expected and does not hold “good” anymore. That is where we need to troubleshoot and find out the problem area.

 

When does it come up? What we can do to eliminate this exception due coding mistakes?

As I have already spoken about the script injection attack can cause this exception, we should not bother about why it is coming up. Rather in that case we can track down the client who is trying to inject the attack and take appropriate action. So I will rather focus upon the scenarios when it comes up due some coding mistakes.

These mistakes are many in number so I would rather cover just a couple of them in this Post:

1.     You have migrated an ASP.NET application from version 1.1 to version 2.0. In 1.1 we had to manipulate the "Select" button column for selecting the record and we normally set the visible property of this button column to FALSE.

The button column has "LinkButton" /”Button” for selecting records and we manually do a Postback using the __dopostback() method.

Agreed that the "LinkButton" /”Button” should register this method for event validation by internally calling the ClientScript.RegisterForEventValidation(). But with the “Visible” property set to FALSE, the control is not rendered and therefore control is not registered for EventValidation by ASP.NET 2.0. However, the DataGrid still utilizes this event. Since the event is not registered, it results in the above error.

In this scenario manually registering the client script for each DataGrid rows will help.

You can simply loop through the rows as mentioned in below code.

            protected override void Render(HtmlTextWriter writer)

{

foreach (DataGridItem row in DataGrid1.Items)

ClientScript.RegisterForEventValidation(row.UniqueID.ToString() +":_ctl0");

base.Render(writer);

}

 

So this signifies that if you are not rendering the control then it is not registered for the validation internally. You need to do that manually using the RegisterForEventValidation function.

 

2.     You have an ASP.NET 2.0 application which has a page with a lot of Javacript adding dynamic controls. On the POST of this particular page you will get the above mentioned exception for Invalid Postback or callback argument. This happens if Javascript is adding a FORM tag as well as adding dynamic controls resulting in the nested form Tags.

This can be reproduced quite easily as well –

In Default.aspx have the below code -

  

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"

Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

<title>Untitled Page</title>

</head>

<body>

<form id="form1" runat="server">

<div>

<asp:Button ID="Button1" runat="server" Text="Button" />

<form></form>

</div>

</form>

</body>

</html>

 

So this signifies that if you have nested form tags the above mentioned error message will come up.

 

So with these two scenarios I will stop at this point. I hope this first post of mine might help you and happy reading.

Published Tuesday, July 31, 2007 9:28 PM by amitsh

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

Tuesday, July 31, 2007 4:46 PM by rahulso

# re: Why I get "Invalid postback or callback argument." Errors?

Welcome to the blogging world Amit!!!

Wednesday, August 01, 2007 8:21 AM by Saurabh Singh

# re: Why I get "Invalid postback or callback argument." Errors?

Welcome in the family :-)

Monday, September 10, 2007 2:58 AM by venkatesh

# re: Why I get "Invalid postback or callback argument." Errors?

Hi..

What must be done to avoid this error? I am using ASP.NET 2.0. I am getting this error in RaisePostBackEvent.

Saturday, September 22, 2007 12:55 AM by amitsh

# re: Why I get "Invalid postback or callback argument." Errors?

You need to use ClientScript.RegisterForEventValidation() for the control causing the postback.

You can share the code and I can have a look.

Wednesday, September 26, 2007 1:23 PM by emonti

# re: Why I get "Invalid postback or callback argument." Errors?

I am getting this error for only a few customers and is infrequent. I just spoke with a user and they told me the rotating banner (new logic and allows flash banners to rotate) on the top of the page was not displaying but a red square, green octagon and blue triangle displayed instead. I had them refresh the page and the banner appeared and the symbols went away and they could continue but the logged in page had the same symbols for banner(refresh cleared it up). We also have a login control(new logic too) that has a javascript onclick event for people logged in.

With most customers not having a problem, i don't know that a fix like the ones recommended are what is required. Any ideas?

Thursday, September 27, 2007 3:50 AM by amitsh

# re: Why I get "Invalid postback or callback argument." Errors?

There are couple of things which you can try to avoid such error. First is simply set EnableEventValidation = false and supress the validation itself.

Else you need to make sure the ClientScript.RegisterForEventValidation() is done for the control on click of which you are doing the postback.

Tuesday, November 13, 2007 3:30 AM by win

# re: Why I get "Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> " Errors?

the progress bar is processing.. and later i click stop button and then i got that error...

Tuesday, November 13, 2007 3:30 AM by win

# re: Why I get "Invalid postback or callback argument. Event validation is enabled using <pages enableEventValidation="true"/> " Errors?

the progress bar is processing.. and later i click stop button and then i got that error...

Tuesday, November 13, 2007 7:01 PM by Babacrash

# re: Why I get "Invalid postback or callback argument." Errors?

I have got a problem with this: I use a component from Infragistics (a tabbed panel control).

To add a close button to the tabs, I use a submit button in a form located in the name of each tab. As a result, I've got nested forms: outside are the tags of the whole page, and inside the tabbed component, are the <form> tags of the buttons.

I can't put the Infragistics component outside of the 'runat=server' tag...

Do you see any way to "unnest" this?

Thanks a lot in advance.

Monday, November 19, 2007 1:16 PM by amitsh

# re: Why I get "Invalid postback or callback argument." Errors?

Hi Win, I have seen this coming if the postback is incomplete as well. Can you please confirm if it comes up even if the postback is complete and I can dig in a bit accordingly?

Thursday, November 22, 2007 12:52 PM by amitsh

# re: Why I get "Invalid postback or callback argument." Errors?

Hi Babacrash, I was trying to repro the scenario which you were talking about. But till now I was not able to achive it yet. May be we can have an email thread going to get to a workaround.

Wednesday, November 28, 2007 7:38 AM by Philip

# re: Why I get "Invalid postback or callback argument." Errors?

Hi

I am having real problems with this error.

I have a page which contains (a) a user control ‘search box’, which uses some Ajax controls [AutocompleteExpender and TextBoxWatermarkExtender] and (b) another user control with a text box and simple buttons ‘for setting the number of rows visible in a GridView’.

These two user controls are contained in an UpdatePanel with the rest of the page not being enclosed in an UpdatePanel (Not my choice, but a management decision).

To refresh the rest of the page outside the UpdatePanel when a user searches or sets the rows using ether of the user control I am using the following code in there respective chick events

ScriptManager.RegisterStartupScript(this.Page, typeof(string), "formSubmit", "document.forms[0].submit();", true);

No mater how I try I can not find which control is causing the error. The screen shot from the error does not give much of a clue, and when trace is enabled I get Render errors cause by the partial postback which happens before the error is hit.

Any suggestion would be most grateful.

Tuesday, December 18, 2007 6:37 AM by David

# re: Why I get "Invalid postback or callback argument." Errors?

Thanks for the article very informative!

Wednesday, January 09, 2008 2:17 AM by michhes

# Why I get "Invalid postback or callback argument." Errors?

Hi amitsh -- The hidden __EVENTVALIDATION field is added near the bottom of the page and, on a slow connection, if I cause a postback while the page is still loading I get this exception. Disabling event validation fixes the problem but is doing that not a security concern?

Michael (mediawhole at hotmail)

Wednesday, January 09, 2008 8:44 AM by amitsh

# re: Why I get "Invalid postback or callback argument." Errors?

It is always a security risk if we disable event validation. I will suggest to disble the postback before the form is fully loaded itself.

Wednesday, January 09, 2008 8:46 AM by amitsh

# re: Why I get "Invalid postback or callback argument." Errors?

Hi Philip, I thik you know the answer to your question. Partial postback is causing this issue. You can eliminate that and the error will go away. You can share the sample if you need help in removing it.

Tuesday, February 19, 2008 4:51 PM by dbl

# re: Why I get "Invalid postback or callback argument." Errors?

Howdy

How can you identify what control on the page is the problem.  I have this error occurring occasionally but not enough to track it down.  I can't "Make" it happen.  My guess is its tied to the AJAX framework but don't have enough to act on it.

Thanks

dbl

Thursday, April 10, 2008 2:22 AM by Nathan

# re: Why I get "Invalid postback or callback argument." Errors?

I m using two dropdownlists within a

update panel using ajax. Here what happens

is I ve written a code for dropdownlist

SelectedIndexChanged event that performs

selection of this dropdownlist will give a

input to the next dropdownlist. the second

ddl will fill its contents based on the

first ddl input. it works fine at first

time when i refresh the page one more time

and was selecting the first ddl. it shows

alert message Invalid postback or callback argument. What should i do now. please help

me    

Friday, April 11, 2008 1:25 PM by amitsh

# re: Why I get "Invalid postback or callback argument." Errors?

Hi Nathan,

Seems like for the first callback the first ddl was registered for the callback but for the subsequent callback it is not being registered. You can actually register the first ddl for callback using ClientScript.RegisterForEventValidation  in Render event.

Thursday, May 01, 2008 1:11 PM by Ginny

# re: Why I get "Invalid postback or callback argument." Errors?

I have a page with a dropdownlist control and I have a javascript that the user can execute to add another item to the dropdownlist control.  If the added item is the selected item when the page posts back then I get this error.  What control needs to be entered in the ClientScript.RegisterForEventValidation method?  When I enter the dropdownlist control I still get the error and when I enter the button control that is posting the page back I still get the error.  So if you could please advise on what control needs to be entered in that method I would greatly appreciate it!

Thanks!

Ginny

Thursday, May 29, 2008 8:57 AM by Ketan

# re: Why I get "Invalid postback or callback argument." Errors?

hiii

This Error Comes Some times And Sometimes not why this happen i can't understand this Sinario.

http://webaspdotnet.blogspot.com/

Wednesday, June 04, 2008 6:50 AM by Abha

# re: Why I get "Invalid postback or callback argument." Errors?

This comes for one of the user of my application when user clicks on the Submit button of the page. can't understand why only one user is getting this error.

can anybody suggest any solution - without any code change.

Friday, June 06, 2008 8:54 AM by babak

# re: Why I get "Invalid postback or callback argument." Errors?

I've got this error using ASP.NET 1.1 !

and can't use ClientScript.RegisterForEventValidation;

so how to solve the problem?

Thanks

Friday, June 06, 2008 9:59 AM by babak

# re: Why I get "Invalid postback or callback argument." Errors?

Solved!

I solved this problem using FrontPage to put Wep Parts on ASP pages!

Saturday, June 07, 2008 2:34 AM by mangokun

# re: Why I get "Invalid postback or callback argument." Errors?

http://aspnet.4guysfromrolla.com/demos/printPage.aspx?path=/articles/122006-1.aspx

   Public Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)

       '###this removes the no forms error by overriding the error

   End Sub

   Public Overrides Property EnableEventValidation() As Boolean

       Get

           Return False

       End Get

       Set(ByVal value As Boolean)

           'DO NOTHING

       End Set

   End Property

Wednesday, October 29, 2008 1:21 PM by Ketan

# re: Why I get "Invalid postback or callback argument." Errors?

Hello There,

 Set EnableEventvalidation=false caused any security reason or not ???

<a href="http://dotnet-magic.blogspot.com/"> ASP.net Discussion</a>

Thursday, November 13, 2008 11:26 AM by Enrique Quispe

# re: Why I get "Invalid postback or callback argument." Errors?

Someone knows how to solve this problem.

Friday, November 14, 2008 2:42 PM by amitsh

# re: Why I get "Invalid postback or callback argument." Errors?

Sorry for being a bit late for responses. Can you guys please post your queries directly to me via email so that I can respond faster?

Thursday, November 20, 2008 2:10 AM by Emad

# Invalid postback or callback argument clicking button before page load

Hi there

I have read almost everypost(virtually) regarding this issue, but my case is a bit different. I even get this error on a simple aspx page having a simple form textboxes and drop downs when there is a page delay and i click the button (titled cancel, and redirects to main page)at the bottom.

As EventValidation comes last contrary to ViewState so if one clicks the button postback occurs, EventValidation is not there ERROR

Any clue?

Saturday, November 22, 2008 3:04 PM by Robin

# re: Why I get "Invalid postback or callback argument." Errors?

Thanks a ton. U solved my problem. The problem was with "nested form tags". I removed them and done!!!

Thursday, December 04, 2008 11:46 PM by JK

# re: Why I get "Invalid postback or callback argument." Errors?

Hi,

Thanks for this nice article. Could you please let me know whether session timeOut can be a reason for the above mentioned exception. If so, what are all the things we should take care?

Regards...

Sunday, December 21, 2008 10:59 PM by sikumar

# re: Why I get "Invalid postback or callback argument." Errors?

<script type="text/javascript">

var pageTracker = _gat._getTracker("UA-203244-1");

pageTracker._trackPageview();

</script>

Sunday, December 21, 2008 10:59 PM by sikumar

# re: Why I get "Invalid postback or callback argument." Errors?

<script type="text/javascript">

var pageTracker = _gat._getTracker("UA-203244-1");

pageTracker._trackPageview();

</script>

Saturday, January 10, 2009 4:21 AM by Puzsol

# re: Why I get "Invalid postback or callback argument." Errors?

For me, it seemed that it was because I was adding a GridView control in the edit cell of another Gridview (don't ask)... and I had AutoGenerateDeleteButton="true"... seems the auto generated controls were just too much for it... but put it in manually... evertying was fine - no need for the RegisterForEventValidation function call either.... sigh.

Tuesday, January 13, 2009 7:19 AM by hounddog howley

# re: Why I get "Invalid postback or callback argument." Errors?

I got this problem because page was not well formed. I'd ported from simple page to one with naster page and left </body> & </form> tags at bottom.

This MAY be your underlying cause.

Good luck

Dave

Thursday, August 06, 2009 1:27 AM by 素人

# re: Why do I get "Invalid postback or callback argument" Errors?

素人ホストでは、男性のテクニック次第で女性会員様から高額な謝礼がもらえます。欲求不満な人妻や、男性と出会いが無い女性達が当サイトで男性を求めていらっしゃいます。興味のある方はTOPページからどうぞ

Friday, August 07, 2009 12:34 AM by 友達募集中

# re: Why do I get "Invalid postback or callback argument" Errors?

さゆのプロフィールが完成しましたぁ。記念すべき初プロフをネットに公開してみました。ドキドキしてるので優しい感想メールしてくれたら心和むかもでぇす po.tomoe.oq@docomo.ne.jp

Saturday, August 08, 2009 12:02 AM by 熟女

# re: Why do I get "Invalid postback or callback argument" Errors?

当サイトではセレブ熟女の性欲を満たしてくれる男性に高額謝礼をお支払いし、デートや一晩のSEX、月契約など選べる逆援出会いの場を作っております。アルバイト感覚でもお待ちしておりますので当サイトで無料登録をどうぞ

Sunday, August 09, 2009 1:02 AM by 家出

# re: Why do I get "Invalid postback or callback argument" Errors?

カワイイ子ほど家出してあそんでみたくなるようです。家出掲示板でそのような子と出会ってみませんか?彼女たちは夕食をおごってあげるだけでお礼にHなご奉仕をしてくれちゃったりします

Tuesday, August 11, 2009 12:36 AM by 逆援助

# re: Why do I get "Invalid postback or callback argument" Errors?

出会ぃも今は逆援助!オンナがオトコを買う時代になりました。当サイトでは逆援希望のセレブ女性が男性を自由に選べるシステムを採用しています。経済的に成功を収めた女性ほど金銭面は豊かですが愛に飢えているのです。興味のある方はどうぞ

Wednesday, August 12, 2009 12:07 AM by 出会い

# re: Why do I get "Invalid postback or callback argument" Errors?

即ハメセレブは完全無料でご利用できる出会いコミュニティです。今までにない実績で、あなたの希望に合った人をお探しします。毎月考えられない豪華なイベントを開催しているので出会いを保障します

Thursday, August 13, 2009 5:27 AM by 救援部

# re: Why do I get "Invalid postback or callback argument" Errors?

夏真っ盛り!女の子は開放的な気分で一人Hしたくてウズウズしてるっ!貴方は女の子のオ○ニーを見て気分を高めてあげてネ!もちろん、お手伝いしてもオッケーだよ!さぁ、今すぐ救援部にアクセスしよっ

Friday, August 14, 2009 5:53 AM by メル友

# re: Why do I get "Invalid postback or callback argument" Errors?

プロフ見て興味ある方は連絡ください。基本的には携帯依存症なぐらい携帯いじるのとかメールするの好きなのでまずはメアドから交換しましょう。仲良くなったら電話もおっけーなんでよろしくo.natyu.natyu.o@docomo.ne.jp

Saturday, August 15, 2009 5:31 AM by 出会い

# re: Why do I get "Invalid postback or callback argument" Errors?

大好評の逆ナンイベントが毎週開催決定!素敵な出会いのきっかけ探し・アイナビにきませんか?積極的な出会いを求める人達なら無料参加OK!あなたもほんの少しの勇気で素敵な彼氏・彼女をGETしちゃおう!

Sunday, August 16, 2009 5:39 AM by 家出

# re: Why do I get "Invalid postback or callback argument" Errors?

夏休みで家出する女の子が急増しています。最初はマンガ喫茶やネットカフェで過ごすことが多いようですが、すぐにお小遣いが無くなり家出掲示板で泊めてくれたり遊んでくれる男性を探す子が多いようです。当サイトはそんな女の子達をサポートしたいという人たちと困っている女性たちの為のサイトです

Monday, August 17, 2009 7:46 AM by 玉の輿度チェッカー

# re: Why do I get "Invalid postback or callback argument" Errors?

当サイトは、みんなの「玉の輿度」をチェックする性格診断のサイトです。ホントのあなたをズバリ分析しちゃいます!玉の輿度チェッカーの診断結果には、期待以上の意外な結果があるかも

Thursday, August 20, 2009 2:07 AM by セレブラブ

# re: Why do I get "Invalid postback or callback argument" Errors?

毎月10万円を最低ラインとする謝礼を得て、セレブ女性に癒しを与える仕事があります。無料登録した後はメールアプローチを待つだけでもOK、あなたもセレブラブで欲求を満たしあう関係を作ってみませんか

Friday, August 21, 2009 1:24 AM by ほむぺ完成記念

# re: Why do I get "Invalid postback or callback argument" Errors?

よーやくプロフ持ちになれました。私の事気になった方がいましたら気軽にメールください。恋バナとか好きなんでよろしくでぇす。zuttozuttoissyodayo@docomo.ne.jp

Saturday, August 22, 2009 1:33 AM by 出張ホスト

# re: Why do I get "Invalid postback or callback argument" Errors?

女性会員様増加につき、当サイトの出張ホストが不足中です。女性の自宅やホテルに出向き、欲望を満たすお手伝いをしてくれる男性アルバイトをただいま募集していますので、興味のある方はTOPページから無料登録をお願いいたします

Sunday, August 23, 2009 1:54 AM by 家出

# re: Why do I get "Invalid postback or callback argument" Errors?

最近様々なメディアで紹介されている家出掲示板では、全国各地のネットカフェ等を泊り歩いている家出少女のメッセージが多数書き込みされています。彼女たちはお金がないので掲示板で知り合った男性とすぐに遊びに行くようです。あなたも書き込みに返事を返してみませんか

Monday, August 24, 2009 2:40 AM by モテる度チェッカー

# re: Why do I get "Invalid postback or callback argument" Errors?

あなたのモテ度数を診断できる、モテる度チェッカー!日頃モテモテでリア充のあなたもそうでないヒキニートの貴方も隠されたモテスキルを測定して今以上にモッテモテになること間違いなし

Tuesday, August 25, 2009 1:20 AM by 救援部

# re: Why do I get "Invalid postback or callback argument" Errors?

オ○ニーライフのお手伝い、救援部でHな見せたがり女性からエロ写メ、ムービーをゲットしよう!近所の女の子なら実際に合ってHな事ができちゃうかも!?夏で開放的になっている女の子と遊んじゃおう

Wednesday, August 26, 2009 1:17 AM by 逆援助

# re: Why do I get "Invalid postback or callback argument" Errors?

メル友募集のあそび場「ラブフリー」はみんなの出逢いを応援する全国版の逆援助コミュニティーです!女の子と真剣にお付き合いしたい方も、複数の女性と戯れたい方も今すぐ無料登録からどうぞ

Thursday, August 27, 2009 12:28 AM by 倶楽部

# re: Why do I get "Invalid postback or callback argument" Errors?

簡単にお小遣い稼ぎをしたい方必見、当サイト逆¥倶楽部では無料登録して女性の性の欲求に応えるだけのアルバイトです。初心者でもすぐに高収入の逆¥交際に興味をもたれた方はTOPページまでどうぞ。

Friday, August 28, 2009 1:21 AM by プロフ公開

# re: Why do I get "Invalid postback or callback argument" Errors?

プロフ作りました。興味ある方連絡まってま〜す。メアドを乗せておくので連絡ください。色んな人の色んな話聞きたい感じですのでヨロシクhappy-my-life-.-@docomo.ne.jp

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker