Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 27, 2011 07:31 AM by master of the maze
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.
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???
Oct 15, 2007 07:20 AM|LINK
You were absolutely right! After putting into (!IsPostBack), the error's gone!
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;
gridview contains a button template field, which on click, Redirect fires.
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.
Dec 20, 2007 08:48 AM|LINK
Setting EnableEventValidation="False" definately works for me...
(if you don;t mind disabling a security feature [;)])
Dec 27, 2007 07:17 AM|LINK
Dec 27, 2007 07:50 AM|LINK
Jan 03, 2008 09:52 AM|LINK
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.
Apr 04, 2008 12:48 PM|LINK