For those of you who get this problem when hitting a button inside a GridView, DataList, Repeater... be sure to put the DataSource instruction which you may have in Page_Load inside a "if (!IsPostBack)". If not implemented like this, as your button hitting
causes a post back, Page_Load is executed again so the Grid or whatever is also refilled again and then it is in that moment when something goes wrong.
I'm also running into this, though not doing any databinding during Page_Load.
I have a FormView inside an UpdatePanel with a LinkButton that changes the FormView's mode from ReadOnly to Edit.
The problem can be reproduced when:
1.) Page is loaded, displaying FormView in ReadOnly mode.
2.) LinkButton is clicked, and the FormView is asynchronously refreshed into Edit mode (remember, it's in an UpdatePanel that is triggered by the LinkButton)
3.) User navigates to another page
4.) User navigates back to the FormView page, which loads in ReadOnly mode
5.) User clicks the LinkButton again.
It makes sense that this error would get thrown because of a discrepancy between the two FormView modes. When the user navigated away from the page, it was in Edit mode (with TextBoxes, DropDownlists, and other input fields). When the user returned to the
page using their browser history, it rendered in ReadOnly mode. When the LinkButton is clicked the second time, it raises LoadPostData on the input controls that are rendered in Edit mode. However the NameValueCollection passed to LoadPostData is the collection
from the form when it's in ReadOnly mode.
Correct me if I'm wrong, but I believe it works like this because the browser does not cache asynchronous updates to the page source, though it DOES cache the postback data. No events seem to be triggered when the page is navigated back to, so the browser's
source for the page is out of sync with the post data collection (both are pulled from browser memory, without checking the server). This problem could be solved if I could figure out how to render the FormView in Edit mode instead of ReadOnly mode when the
user navigates back to the page using their browser history, but therein lies the problem -- the server is not notified of this navigation.
So, here's my question: If the FormView is completely contained within a LoginView such that it is only rendered for logged-in users in a specific role, is there still a huge security risk to set EnableEventValidation to false? Would this setting make it
any easier for a hacker to trick ASP.NET into running under a specific user or identity? Or, does ASP.NET even validate the identity of an alien form trying to submit data to input fields wrapped inside of a LoginView???
My Signature: Mark a post as answered if it helped you, or don't, it makes no difference to me. Just PLEASE try not to use the word "random" when describing your problem.
What siizuka says seems correct. I checked to make sure I'm doing a databind() only if the page is NOT postback. This seems to have fixed the problem. The OnItemCommand
event fires just fine now.
I have a datagrid whaich has only one TemplateColumn.This TemplateColumn has label and a button.The Button has a CommandName.Html Code is give below:-
At codeBehind I have ItemCommand Event.But whenever I Click the "Add" Button I get an error Invalid postback or callback argument. Event validation is enabled using in configuration or in a page After setting EnableEventValidation to false, i was able to remove
the error but i m not able to fire the Code Behing event. Can somebody help me?
I have not read the last 2 pages, so appologies if my solution is already there. I was getting the same error as you guys but my source was a linkbutton that I was using to do a search and fill a dropdown list.
The problem arose when I pressed the search button twice. The dropdown list was in an updatepanel, and the search button was not. the first time I pressed it it did a partial postback as expected, but the second time it tried to do a postback for the whole
page and I guess something somewhere got out of sinc.
I placed the search button in an update panel and now no more error.
Thanks a lot for your kind answer. I was resetting SelectCommand property of the gridview component in my page in PageLoad section and was having that EnableEventValidation error problem and now using your suggestion to check IsPostBack solved it.
ahoms
Member
2 Points
2 Posts
Re: error: enableEventValidation="true"/
Aug 24, 2007 02:32 PM|LINK
For those of you who get this problem when hitting a button inside a GridView, DataList, Repeater... be sure to put the DataSource instruction which you may have in Page_Load inside a "if (!IsPostBack)". If not implemented like this, as your button hitting causes a post back, Page_Load is executed again so the Grid or whatever is also refilled again and then it is in that moment when something goes wrong.
danludwig
Contributor
3020 Points
601 Posts
Re: error: enableEventValidation="true"/
Aug 24, 2007 10:56 PM|LINK
I'm also running into this, though not doing any databinding during Page_Load.
I have a FormView inside an UpdatePanel with a LinkButton that changes the FormView's mode from ReadOnly to Edit.
The problem can be reproduced when:
1.) Page is loaded, displaying FormView in ReadOnly mode.
2.) LinkButton is clicked, and the FormView is asynchronously refreshed into Edit mode (remember, it's in an UpdatePanel that is triggered by the LinkButton)
3.) User navigates to another page
4.) User navigates back to the FormView page, which loads in ReadOnly mode
5.) User clicks the LinkButton again.
It makes sense that this error would get thrown because of a discrepancy between the two FormView modes. When the user navigated away from the page, it was in Edit mode (with TextBoxes, DropDownlists, and other input fields). When the user returned to the page using their browser history, it rendered in ReadOnly mode. When the LinkButton is clicked the second time, it raises LoadPostData on the input controls that are rendered in Edit mode. However the NameValueCollection passed to LoadPostData is the collection from the form when it's in ReadOnly mode.
Correct me if I'm wrong, but I believe it works like this because the browser does not cache asynchronous updates to the page source, though it DOES cache the postback data. No events seem to be triggered when the page is navigated back to, so the browser's source for the page is out of sync with the post data collection (both are pulled from browser memory, without checking the server). This problem could be solved if I could figure out how to render the FormView in Edit mode instead of ReadOnly mode when the user navigates back to the page using their browser history, but therein lies the problem -- the server is not notified of this navigation.
So, here's my question: If the FormView is completely contained within a LoginView such that it is only rendered for logged-in users in a specific role, is there still a huge security risk to set EnableEventValidation to false? Would this setting make it any easier for a hacker to trick ASP.NET into running under a specific user or identity? Or, does ASP.NET even validate the identity of an alien form trying to submit data to input fields wrapped inside of a LoginView???
glimmerOfHop...
Member
22 Points
11 Posts
Re: error: enableEventValidation="true"/
Oct 15, 2007 07:20 AM|LINK
Hi ahoms,
You were absolutely right! After putting into (!IsPostBack), the error's gone!
Thanks!
RezaOli
Member
2 Points
1 Post
Re: error: enableEventValidation="true"/
Oct 30, 2007 07:50 AM|LINK
i did it! place the Page_load in a condition like this:
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack != true)
{
GridView1.DataSource = ObjectDataSourcePrimary;
GridView1.DataBind();
}
}
gridview contains a button template field, which on click, Redirect fires.
ahikiran
Member
4 Points
2 Posts
Re: error: enableEventValidation="true"/
Nov 26, 2007 04:48 PM|LINK
What siizuka says seems correct. I checked to make sure I'm doing a databind() only if the page is NOT postback. This seems to have fixed the problem. The OnItemCommand event fires just fine now.
DavidWalker
Member
8 Points
4 Posts
Re: error: enableEventValidation="true"/
Dec 20, 2007 08:48 AM|LINK
Setting EnableEventValidation="False" definately works for me...
(if you don;t mind disabling a security feature [;)])
arshi
Member
13 Points
13 Posts
Re: error: enableEventValidation="true"/
Dec 27, 2007 07:17 AM|LINK
arshi
Member
13 Points
13 Posts
Re: error: enableEventValidation="true"/
Dec 27, 2007 07:50 AM|LINK
deathbyveget...
Member
2 Points
1 Post
Re: error: enableEventValidation="true"/
Jan 03, 2008 09:52 AM|LINK
Hi everyone,
I have not read the last 2 pages, so appologies if my solution is already there. I was getting the same error as you guys but my source was a linkbutton that I was using to do a search and fill a dropdown list.
The problem arose when I pressed the search button twice. The dropdown list was in an updatepanel, and the search button was not. the first time I pressed it it did a partial postback as expected, but the second time it tried to do a postback for the whole page and I guess something somewhere got out of sinc.
I placed the search button in an update panel and now no more error.
hope this helps someone somewhere.
UydurukAdres
Member
10 Points
5 Posts
Re: My problem solved!
Apr 04, 2008 12:48 PM|LINK