admin管理员组

文章数量:1313806

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?

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?

Share Improve this question asked Aug 16, 2012 at 10:28 ElliottElliott 2,7292 gold badges24 silver badges33 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Just figured this out.

The solution

The __EVENTARGUMENT can simply be cleared in the following way:

theForm.__EVENTARGUMENT.value = '';

If it is necessary to perform this action every time an <asp:UpdatePanel> loads, then put the following inside your UpdatePanel:

<script type="text/javascript">
    Sys.Application.add_load(function () {
        theForm.__EVENTARGUMENT.value = '';
    });
</script>

 


Reason:

The majority of .Net controls use the javascript __doPostBack function to handle postbacks, so the following code will automatically be added to the page when it is generated:

<script type="text/javascript">
//<![CDATA[
var theForm = document.forms['form'];
if (!theForm) {
    theForm = document.form;
}
function __doPostBack(eventTarget, eventArgument) {
    if (!theForm.onsubmit || (theForm.onsubmit() != false)) {
    theForm.__EVENTTARGET.value = eventTarget;
    theForm.__EVENTARGUMENT.value = eventArgument;
    theForm.submit();
    }
}
//]]>
</script>

This is where the value is set for __EVENTARGUMENT, and therefore what is referenced from the codebehind.

本文标签: cClear eventArgumentStack Overflow