I have a form with an <asp:UpdatePanel> and 2 <asp:button> controls to Save and Reset the form. I am triggering the <asp:UpdatePanel> using a javascript __doPostBack() function and passing a value in it’s __EVENTARGUMENT if the panel should be reset.
My codebehind checks for a value on PreRender via
Request.Params.Get("__EVENTARGUMENT")
to determine whether to reset the form with it’s original data or not.
If the panel was previously reset, the __EVENTARGUMENT seems to linger when the save button is pressed, therefore resetting my form again on postback.
I have tried to clear the __EVENTARGUMENT in the Page_Load using:
Request.Params.Clear();
and
Request.Params.Set("__EVENTARGUMENT", "");
but the collection is read only. I found on another post, using javascript:
window.document.getElementById('__EVENTARGUMENT').value = '';
but this doesn’t seem to work either. Any ideas?
Just figured this out.
The solution
The
__EVENTARGUMENTcan simply be cleared in the following way:If it is necessary to perform this action every time an
<asp:UpdatePanel>loads, then put the following inside your UpdatePanel:Reason:
The majority of .Net controls use the javascript
__doPostBackfunction to handle postbacks, so the following code will automatically be added to the page when it is generated:This is where the value is set for
__EVENTARGUMENT, and therefore what is referenced from the codebehind.