I am receiving this error when I click on the button to log into Facebook from my website.
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.
When searched Google and found these two links so I can understand the error message. However they did not fix the problem.
asp.net: Invalid postback or callback argument
http://blogs.msdn.com/b/amitsh/archive/2007/07/31/why-i-get-invalid-postback-or-callback-argument-errors.aspx
So I took apart the page section by section until I found what was causing the error. It was this:
iframe name="ContentIFrame" class="IFrameStyle"
When I delete the iframe, everything works. However, I need the iframe on the page. Can anyone assist why the iframe is causing this error? It has nothing to do with Postback.
While I have seen suggestions to disable event validation (setting EnableEventValidation=false), I do not recommend that approach as it could create security problems. In my case, what resolved the problem was to use an asp:PlaceHolder instead of directly placing the iframe into the ASPX. Then, in the C# code, I add a new HtmlIframe control to the placeholder's ControlCollection:
Place the following in the ASPX:
<asp:PlaceHolder runat="server" ID="myPlaceholder" />
Then, place the following in the postback handler:
using System.Web.UI.HtmlControls;
HtmlIframe newIframe = new HtmlIframe();
newIframe.Src = "somewhere/some_page.html";
myPlaceholder.Controls.Add(newIframe);
An alternative is to place the iframe directly into the ASPX and to set the HTML element as runat="server". Once runat="server" has been set, you should be able to access the control's ID from within your code to set the src attribute.
Related
I am getting the below detailed error:
Invalid postback or callback argument. Event validation is enabled using in configuration or <%# Page EnableEventvalidation =”true” %> in a page. For security purpose, this feature verifies that arguments to postback or callback events originate from the server that originally rendered them.
I am having a webpart page with a webpart where i do have a UPdatePanel and a button Upon Button click i am getting this error.
the same package(wsp) which we are using in one of our environment is working fine and the same is not working in another environment.
Help in this is highly appreciable.
Without code it will be incredibly difficult to diagnose your issue.
You mentioned that your utilizing an Update Panel, which in essence will automatically store your page in memory, then it will render the proper Ajax to hide the Postback. The Microsoft Developer Network (MSDN) basically warns you when you use the EnableEventValidation with Client-Side modification.
If you write client script that changes a control in the client at run
time, you might have to use the RegisterForEventValidation method in
order to avoid false event validation errors.
Also if you initialize out of your web.config and directly in code, you should ensure that you call the validation before the page has been initialized. So I would potentially use:
protected void Page_PreInit()
{
// Before Page Initialization
}
Which would potentially eliminate any errors from the front-end, without code can't be of more assistance.
Ok without some code to go on I'll fire some rounds off into the dark, I know next to nothing about SharePoint so I maybe missing something obvious here:
Firstly, check your environments, one may have a different web.config which has EnableEventValidation set to false.
Secondly on Page_Load are you doing any DataBind? Depending on whatever your code is doing you may need make sure it's not binding on PostBack - or if it is already; try binding on PostBack.
Thirdly; any html or < > characters being included anywhere in the form? Also line breaks in data (my memory is a bit hazy on this one) I seem to remember, something like:
<option value="
my value
">select this</option>
Could cause it too. So doing a Trim() on data is recommended.
Lastly: Tag bleed out, check none of your tags are unclosed, something like <span <asp:TextBox [...] /> this could be the cause too.
add EnableEventValidation="false" in page directive <%# Page EnableEventValidation="false" %>
I am using a repeater and I am getting this error after clicking the button (with a Command)
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.
I did some research, and I read that I need to set EnableViewState=”false”, didn't work.\
Also tried that in the web.config file, didn't work.
Used also updatepanel: same problem.
What is this kind of error? In my previous ASP project this worked fine for me without changing settings.
Can anyone help me?
Without seeing your code, my guess is that you are binding the data for your control before the events are fired (i.e. data binding in the Page_Load, because that is called before the event handler code).
You need to only bind the data in Page_Load when the page is not a postback (i.e. first load of the page and not from event clicks), like this:
if(!Page.IsPostBack)
{
// Bind repeater data here
}
Then at the end of your event handler (i.e. your command click), then you should re-bind the data as the last line of that method or part of the method where you have the logic pertinent to the user clicking.
I have got a button field in my grid view. When I click multiple times on the grid (3 times), I am getting an error which is shown below. The same issue is arised when I click multiple times on a page number(which is not the active page) of the grid.
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.
Please help me solve the issue.
I guess you have added databinding code in page load without enclosing IsPostBack block.
void page_load()
{
if(!IsPostBack)
{
//put databinding code here
}
}
EDIT:
Please read these threads/posts:
Invalid postback or callback argument. Event validation is enabled using ''
MSDN blog - Validation of viewstate MAC failed error
Validation of viewstate MAC failed
Validation of viewstate MAC failed error
I'm working on a web form which works in a following way.
Read email template from database
Display email template on a web form in HTML format
User adds additional information to the web form and clicks on submit button
Before I get to a method which will process that request, I get A potentially dangerous Request.Form
I have looked at few articles that advise using .Net 2.0 in one of the web.config sections - that didn't work. I have set requestValidation = "false" for that page and it didn't work either.
My gut feeling is that I'm doing something fundamentally wrong...
HTML template is stored as VarChar(4000) in a database.
I have tried encoding text in a method before I send an email, but that didn't work either because the web form never got to executing that method.
What other options do I have? I have tried storing plain text in database, but then I have issue of tabs and returns etc.
Thank you
The remedy is in two parts and you MUST action both:
To disable request validation on a page add the following directive to the existing "page" directive in the file (you will need to switch to the HTML view for this):
ValidateRequest="false"
for example if you already have:
<%# Page Language="vb" AutoEventWireup="false"
Codebehind="MyForm.aspx.vb"
Inherits="Proj.MyForm"%>
then this should become:
<%# Page Language="vb" AutoEventWireup="false"
Codebehind="MyForm.aspx.vb"
Inherits="Proj.MyForm"
ValidateRequest="false"%>
In later versions of Visual Studio the value of this property is available via the page properties, so simply set "ValidateRequest" to "False". Either method of setting this achieves the same result.
Alternately, you can globally turn request validation off (but in which case be sure to implement item two below). To globally turn request validation off add the following to your web.config file:
<pages validateRequest="false" />
From: http://www.cryer.co.uk/brian/mswinswdev/ms_vbnet_server_error_potentially_dangerous.htm
As a first security lesson, never trust user input,so if you setting request validation to false then always HTML encode the input.
In basic either use: OnClientClick on submit and replace, < with & lt; and > with & gt; (no space with & and gt/lt)
or on submit method, use Server.HTMLEncode(inputtext)..or however you process it.
I have a menu usercontrol called LeftMenu that has a bulletedlist of linkitems. It's on the ascx page as such:
<asp:BulletedList ID="PublisherList" DisplayMode="LinkButton" OnClick="PublisherList_Click" cssClass="Menu" runat="server"></asp:BulletedList>
I databind the list in the page_load under if(!isPostBack)
I'm having an issue on a page that loads the control. When the page first loads, the event handler fires. However, when the page posts back it no longer fires and in IE8, when I'm debugging, I get "Microsoft JScript runtime error: Object expected" in Visual Studio pointing at "__doPostBack('LeftMenu$PublisherList','0')." In FF I don't get the error, but nothing happens. I'm not loading the control dynamically, it's loaded on the aspx page using:
<%# Register TagPrefix="Standards" TagName="LeftMenu" Src="LeftMenu.ascx" %>
<Standards:LeftMenu ID="LeftMenu" runat="server"/>
Any ideas of where I'm losing the event handler?
I just realized this is happening on another user control I have as well. A text box and a button and I'm using the default button to make sure pressing the enter key uses that button. .Net converts that in the html to:
<div id="SearchBarInclude_SearchBar" onkeypress="javascript:return WebForm_FireDefaultButton(event, 'SearchBarInclude_QuickSearchButton')">
so as soon as i enter a key in the box I get a javascript error at the line saying "object expected." It seems like the two issues are related.
Edit Again: I think I need to clarify. It's not that I'm clicking on the menu item and it can't find the selected item on postback. I have this search page with the left navigation on it and then the main content of the page is something that causes a postback. Everything is fine with this postback. Once that page has been posted back, now if I click on the bulleted list in the left navigation I get a javascript error and it fails. The page_init for the LeftMenu control is never called.
It sounds like you might be losing the click because you are not DataBinding the list on PostBack. Therefore, the post back is trying to refer to a control (a specific bulleted list item) that does not exist.
You should try binding the list again on PostBack just to see if that fixes your issue. BUT, what should REALLY happen is that the LeftMenu and the BulletedList should store their information into ViewState so that you can ensure that the data that was shown to the user on their initial page load is the same data that the PostBack is processing and working with.
If you have EnableViewState=true for your UserControl and all controls within it, everything should work fine. With ViewState enabled, ASP will reinflate your controls from ViewState after Init has fired. This means that the postback event arg (which points to an index in your control list) will still find the control in that list position. Otherwise the list is empty on postback.
However, ViewState is the work of the devil and was designed simply to foster the illusion that you are working in a stateful environment. It is okay to use it for small amounts of data but typically not advisable for templated controls like repeaters and lists because you have no idea how much data is going to be created in ViewState.
If you are dealing with static, or relatively static data, store it in the application cache and rebind your lists in Page.Init every time (note that it has to be in Init because post-init is when ASP rebinds from ViewState; if you get in there first, your data will be used instead).
If you are dealing with volatile data, you have a problem because the data you rebind must be exactly the same as the original page request, otherwise the postback events will be firing against the wrong rows. In that case you need to either store your initial data in Session or you simply store the list of rows ids (in a hidden variable or Session) and you recreate the data to bind against from the ids each time.
An even better solution is to not use postback events at all. Try to turn all your events into GETs that have an ID on the query string. You can still create the list using binding the first time through the page (as you are currently doing), and you can even GET the same page with a new ID.
If you need to keep state on the same page but need to respond to the user changing a radio button selection (or something else), think about using Ajax calls to update the screen. You also do that with an ID that you pass to the Ajax call.
In general, the more you move from using stateful ASP, the lighter and more responsive your pages will become. You will also be in a better position to move to stateless MVC if necessary. You will also save lots of time lost to debugging obscure problems because ViewState is not available when you need it to be.
The best analysis of ViewState I've read is in the link below. If you fully understand how it works, you can continue to use it without necessarily incurring the costs.
http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/truly-understanding-viewstate.aspx
It's possible that this might be javascript related, and that a script that is loading earlier in the page is throwing an error and causing the page to not be loaded properly.
Are your usercontrols loading any javascript onto the page? Can you check for javascript errors on the initial load of the page?
I moved the code into an existing project we have and for some strange reason, I stopped getting the javascript errors and instead got:
"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."
I haven't quite figured out where I'm supposed to put the register event validation with a user control, but in the mean time I just set enableeventvalidation=false and it seems to work now.
It looks like the doPostBack function is missing since its arguments are literals so they couldn't be the cause. Is that one of your own functions or did you mean to call the ASP __doPostBack function?
Have a look at the Firefox error console or allow script debugging in IE and see exactly what object can't be found. Even better, download Firebug and debug it.
I had a similar issue. It turned out that Akamai was modifying the user-agent string because an setting was being applied that was not needed.
This meant that some .NET controls did not render __doPostBack code properly. This issue has been blogged here.