Saturday, March 24, 2012

PageRequestManagerServerErrorException when using UrlMappings


I think I found a bug and I would like some help about a workaround.

I have a page with DropDownList inside an UpdatePanel. The page path is /physicalfolder/physicalpage.aspx

1 <form id="form1" runat="server">2 <asp:ScriptManager ID="ScriptManager1" runat="server" />3 <asp:UpdatePanel ID="PanelRecherche" runat="server" Visible="true" UpdateMode="Conditional">4 <ContentTemplate>5 <table><tr> <td>6 <asp:DropDownList ID="dropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="dropDownList1_SelectedIndexChanged"/>7 </td></tr> </table>8 </ContentTemplate>9 </asp:UpdatePanel>10 <button type="submit">Go</button>11 </form>

In the code behind I do nothing except adding items to the DropDownList

1protected void Page_Load(object sender, EventArgs e)2 {3if (!Page.IsPostBack && !ScriptManager1.IsInAsyncPostBack)4 {5 dropDownList1.Items.Add("1");6 dropDownList1.Items.Add("2");7 }8 }910protected void dropDownList1_SelectedIndexChanged(object sender, EventArgs e)11 {1213 }

And finally in the web.config file I've set some UrlMappings

1<urlMappings>2 <add url="~/virtualfolder/virtualpage.aspx" mappedUrl="~/physicalfolder/physicalpage.aspx"/>3</urlMappings>

The problem is the following: when usinghttp://localhost/mysite/physicalfolder/physicalpage.aspx everything works fine, I can play as much as I want with the DropdownList.

If I use the vrtual pathhttp://localhost/mysite/virtualfolder/virtualpage.aspx only the first postback works fine, after that I get an error :

Microsoft Internet Explorer
Sys.WebForms.PageRequestManagerServerErrorException: An unknown error occurred while processing the request on the server. The status code returned from the server was: 404

If I look at the http requests:

    To access the page the first timehttp://localhost/mysite/virtualfolder/virtualpage.aspxOn First index change http://localhost/mysite/physicalfolder/physicalpage.aspxOn next index changes http://localhost/mysite/virtualfolder/physicalpage.aspx

Funny thing is that if I use the submit button before doing something else, it works like a charm.

Any ideas ? I can't remove UrlMapping and I need AjaxCrying

Ok, found it by my self, I was using wrong search patern.

Added this code right after closing form:

1 <script type="text/javascript">2 Sys.Application.add_load(function()3 {4 var form = Sys.WebForms.PageRequestManager.getInstance()._form;5 form._initialAction = form.action = window.location.href;6 });7 </script>

No comments:

Post a Comment