Http://www.cnblogs.com/frogbag/archive/2007/03/16/676768.htmlSys.WebForms.PageRequestManagerServerErrorException (status code 500 or 12031)
We only need to respond to SYS. the load event of the application will be triggered when the page is loaded for the first time and after each partial rendering. At this time, we can modify the action attribute of the form element on the page, as shown below:
Load event of corresponding SYS. Application
SYS. application. add_load (function ()
{
VaR form = SYS. webforms. pagerequestmanager. getinstance (). _ form;
Form. _ initialaction = form. Action = Window. Location. href;
});
The updatepanel implementation method is required for obtaining the form element, _ initialaction, and setting it in this way. I will not explain it here. As long as such a small segment is placed in the page Code This problem is solved.
In-depth questions:
The reason for this problem is that after URL rewrite, the action of the form element is not the Address requested by the client, but the target address of URL rewrite. If we do not use partial rendering, but use the most traditional PostBack, although the page function will not be damaged, after the PostBack, the user will find that the content in the address bar has changed, directly changed to the target address. This is not the expected result. Now that rewrite is complete, rewrite it to the end. Of course, we can still use the method mentioned above to use JavaScript to modify the action of the form element, but this practice is not "elegant and generous ", in addition, you can see the target URL rewrite address from the HTML source file, right?
If we can set the form action on the server side, it is a pity that the system. Web. UI. htmlcontrols. htmlform class does not allow us to do this. But fortunately, we use ASP. NET, and we use an object-oriented programming model. Therefore, we "inherit" system. Web. UI. htmlcontrols. htmlform to implement a Form Control:
Inherit from the htmlform class to implement its own from
Namespace actionlessform {
Public class form: system. Web. UI. htmlcontrols. htmlform
{
Protected override void renderattributes (htmltextwriter writer)
{
Writer. writeattribute ("name", this. Name );
Base. Attributes. Remove ("name ");
Writer. writeattribute ("method", this. method );
Base. Attributes. Remove ("method ");
This. Attributes. Render (writer );
Base. Attributes. Remove ("action ");
If (base. ID! = NULL)
Writer. writeattribute ("ID", base. clientid );
}
}
}
Then we can use it in the page. Of course, before that, we need to register it on the page (or web. config:
Use our own form
<% @ Register tagprefix = "SKM" namespace = "actionlessform"
Assembly = "actionlessform" %>
...
<SKM: Form ID = "form1" method = "Post" runat = "server">
...
</SKM: Form>
So far, we don't need to write a piece of "clever" javascript in the page, and the action problem of form element after URL rewrite is solved.