Showing posts with label urlmappings. Show all posts
Showing posts with label urlmappings. Show all posts

Wednesday, March 28, 2012

PageMethod problem

HI. I have a problem with calling static PageMethod in asp.net ajax.

Problem apperars then i use UrlMappings. For example i have this code in web.config

<urlMappings>
<add url="~/ComputerManager/WorkstationList.aspx" mappedUrl="~/ComputerManager/ComputerList.aspx?comp_type=1"/>
<add url="~/ComputerManager/ServerList.aspx" mappedUrl="~/ComputerManager/ComputerList.aspx?comp_type=2"/>
</urlMappings>
and this code in ComputerList.aspx. cs
[WebMethod]
public static string SetSelection(string ID,string dataKey,bool state)
{
...
}

so, when call PageMethods.SetSelection(...) a have a error "The server method SetSelection is failed".

post url ends with WorkstationList.aspx/SetSelection

any ideas?

Hi,

You are rewriting your URL, and these URL are fixed one. They don't cater for any extra items or query string parameters. Thats why they don't map to actual page when you want to do that. In this case I will recommend that you add another entry with following items

<urlMappings><add url="~/ComputerManager/WorkstationList.aspx" mappedUrl="~/ComputerManager/ComputerList.aspx?comp_type=1"/><add url="~/ComputerManager/ServerList.aspx" mappedUrl="~/ComputerManager/ComputerList.aspx?comp_type=2"/><add url="~/ComputerManager/WorkstationList.aspx/SetSelection" mappedUrl="~/ComputerManager/ComputerList.aspx?comp_type=1"/><add url="~/ComputerManager/ServerList.aspx/SetSelection" mappedUrl="~/ComputerManager/ComputerList.aspx?comp_type=2"/></urlMappings>

Then i use mappings like you suggested, i get a request to pageComputerList.aspx with parametercomp_type=1, insted of calling PageMethod.

So i rewrite it this way

<urlMappings>
<add url="~/ComputerManager/WorkstationList.aspx" mappedUrl="~/ComputerManager/ComputerList.aspx?comp_type=1"/>
<add url="~/ComputerManager/ServerList.aspx" mappedUrl="~/ComputerManager/ComputerList.aspx?comp_type=2"/>
<add url="~/ComputerManager/WorkstationList.aspx/SetSelection" mappedUrl="~/ComputerManager/ComputerList.aspx/SetSelection"/>
<add url="~/ComputerManager/ServerList.aspx/SetSelection" mappedUrl="~/ComputerManager/ComputerList.aspx/SetSelection"/>
</urlMappings>

and that solves my problem.

Thanks for good idea,ziqbalbh.

Saturday, March 24, 2012

PageRequestManagerServerErrorException when using UrlMappings

Hi,

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
--------
OK
--------

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>