I have an update panel that has a button that expands a section for editing content, however after it loads the content to edit, the postback throws a 404, I can track the pages it's trying to go to as well.
The postback will go to
"/products/prodTemplate.aspx?pageID=6", which doesn't work as products is an 'imaginary" directory
if I set the postback URL on the button explicitly to go to
"~/products/myproduct.aspx", it goes to
"products/products/myproduct.aspx"
This used to work fine in the betas when it was called Atlas, now it's broken. Also have the image button problem where if you click the topmost or leftmost column of pixels in the image, it gives an error.
You must be using a url rewriter module, but which?
If I just do a simple url rewrite from ~/subdir/foo.aspx to ~/bar.aspx it works fine with or without an update panel. So there must be something more to it. If you can build a repro that doesn't use any external libraries (i.e. write your own url rewriting
code) it would help isolate it.
URLMappings are part of ASP .Net 2.0 and are just set in the web.config file in the System.Web configuration section, it's not like I'm using ISAPI rewrite or anything, I think it's a bug introduced between Beta and 1.0 in ASP.Net Ajax.
The problem is on a normal postback, the action initially posts to the "real" url. So the action is emitted in response to the postback as if the url is relative to the real location. Are you seeing that the post initially works, but then only on the 2nd
attempt it fails?
I'll look more into it but you should be able to work around it by manually changing the form action itself.
Try this:
function pageLoad(sender, args) {
if(args.get_isPartialLoad()) {
// update form action
var form = $get('Form1');
form._initialAction = form.action = '../prodTemplate.aspx?pageID=6';
}
}
If your querystring is dynamic you could build the action up from it instead of hard coding it like this. Just be sure to set the form._initialAction as well as the form.action... this is how PageRequestManager detects cross page postbacks, and you don't
want it to think a regular post is a cross page postback.
so it should keep posting to that same URL, not move it up a directory after the first postback and combine the real URL one with the mapped one's directory
setting the postback URL seems like it should work and I should not have to hack to the form action with javascript, I'd rather have a reason why it's doing this than to just put in a work-around.
If you take out the update panel and just do a normal post, you will see that the page will actually post directly to the unmapped url. That means your url rewriting is gone after a postback. That probably isn't what you would want, correct? If you implement
a url rewriting scheme that actually changes what the form action is, so that posts go to the mapped url instead, not only will it avoid this issue, but it will work better in general. With this scheme, you have the possibility of the server side thinking
the current request is in a different directory than the browser thinks, so things like ResolveClientUrl may report unusable paths. Any way you look at it, its best to avoid that scenario in the first place, so I recommend you take a look at the url rewriting
post by Scott Guthrie,
Sys.Application.add_load(function()
{
var form = Sys.WebForms.PageRequestManager.getInstance()._form;
form._initialAction = form.action = window.location.href;
});
I LOVE YOU! I spent many hours today trying to figure out why my update panels were not working with my ISAPI Rewrite site and this just solved it for me. Thank you very much!
Sys.Application.add_load(function()
{
var form = Sys.WebForms.PageRequestManager.getInstance()._form;
form._initialAction = form.action = window.location.href;
});
Thanks a million Jeffrey. I experienced this behavior when moving a working app from IIS7 to IIS6. After adding your script everything worked perfectly in IIS6 as well.
None
0 Points
12 Posts
UpdatePanel posts back to wrong URL when URLMappings used in a "subdirectory"
Mar 06, 2007 02:21 PM|fizgigtiznalkie|LINK
I have an update panel that has a button that expands a section for editing content, however after it loads the content to edit, the postback throws a 404, I can track the pages it's trying to go to as well.
say this is a URL Mapping:
<add url="~/products/myproduct.aspx" mappedUrl="~/prodTemplate.aspx?pageID=6"/>
The postback will go to "/products/prodTemplate.aspx?pageID=6", which doesn't work as products is an 'imaginary" directory
if I set the postback URL on the button explicitly to go to "~/products/myproduct.aspx", it goes to "products/products/myproduct.aspx"
This used to work fine in the betas when it was called Atlas, now it's broken. Also have the image button problem where if you click the topmost or leftmost column of pixels in the image, it gives an error.
UrlMappings UpdatePanel PostBack Subdirectory
Member
510 Points
323 Posts
Re: UpdatePanel posts back to wrong URL when URLMappings used in a "subdirectory"
Mar 06, 2007 04:31 PM|InfinitiesLoop|LINK
You must be using a url rewriter module, but which?
If I just do a simple url rewrite from ~/subdir/foo.aspx to ~/bar.aspx it works fine with or without an update panel. So there must be something more to it. If you can build a repro that doesn't use any external libraries (i.e. write your own url rewriting code) it would help isolate it.
Infinities Loop: TRULY Understanding ViewState
.NET from a new perspective.
This posting is provided "AS IS".
None
0 Points
12 Posts
Re: UpdatePanel posts back to wrong URL when URLMappings used in a "subdirectory"
Mar 06, 2007 09:02 PM|fizgigtiznalkie|LINK
http://msdn.microsoft.com/en-us/library/system.web.configuration.urlmappingssection.aspx
URLMappings are part of ASP .Net 2.0 and are just set in the web.config file in the System.Web configuration section, it's not like I'm using ISAPI rewrite or anything, I think it's a bug introduced between Beta and 1.0 in ASP.Net Ajax.
Member
510 Points
323 Posts
Re: UpdatePanel posts back to wrong URL when URLMappings used in a "subdirectory"
Mar 07, 2007 02:07 PM|InfinitiesLoop|LINK
The problem is on a normal postback, the action initially posts to the "real" url. So the action is emitted in response to the postback as if the url is relative to the real location. Are you seeing that the post initially works, but then only on the 2nd attempt it fails?
I'll look more into it but you should be able to work around it by manually changing the form action itself.
Try this:
function pageLoad(sender, args) {
if(args.get_isPartialLoad()) {
// update form action
var form = $get('Form1');
form._initialAction = form.action = '../prodTemplate.aspx?pageID=6';
}
}
If your querystring is dynamic you could build the action up from it instead of hard coding it like this. Just be sure to set the form._initialAction as well as the form.action... this is how PageRequestManager detects cross page postbacks, and you don't want it to think a regular post is a cross page postback.
Infinities Loop: TRULY Understanding ViewState
.NET from a new perspective.
This posting is provided "AS IS".
None
0 Points
12 Posts
Re: UpdatePanel posts back to wrong URL when URLMappings used in a "subdirectory"
Mar 07, 2007 03:15 PM|fizgigtiznalkie|LINK
so it should keep posting to that same URL, not move it up a directory after the first postback and combine the real URL one with the mapped one's directory
setting the postback URL seems like it should work and I should not have to hack to the form action with javascript, I'd rather have a reason why it's doing this than to just put in a work-around.
None
0 Points
8 Posts
Re: UpdatePanel posts back to wrong URL when URLMappings used in a "subdirectory"
Apr 18, 2007 05:40 PM|anthony.sena|LINK
We are experiencing the same problem described in this post. Are there any insights besides the JavaScript work-around described here?
Thanks!
Member
510 Points
323 Posts
Re: UpdatePanel posts back to wrong URL when URLMappings used in a "subdirectory"
Apr 18, 2007 05:53 PM|InfinitiesLoop|LINK
If you take out the update panel and just do a normal post, you will see that the page will actually post directly to the unmapped url. That means your url rewriting is gone after a postback. That probably isn't what you would want, correct? If you implement a url rewriting scheme that actually changes what the form action is, so that posts go to the mapped url instead, not only will it avoid this issue, but it will work better in general. With this scheme, you have the possibility of the server side thinking the current request is in a different directory than the browser thinks, so things like ResolveClientUrl may report unusable paths. Any way you look at it, its best to avoid that scenario in the first place, so I recommend you take a look at the url rewriting post by Scott Guthrie,
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
Infinities Loop: TRULY Understanding ViewState
.NET from a new perspective.
This posting is provided "AS IS".
Member
10 Points
20 Posts
Re: UpdatePanel posts back to wrong URL when URLMappings used in a "subdirectory"
Apr 18, 2007 11:51 PM|JeffreyZhao|LINK
Add this to your page:
Technical consultant & trainer
None
0 Points
16 Posts
Re: UpdatePanel posts back to wrong URL when URLMappings used in a "subdirectory"
Aug 21, 2008 04:44 PM|vipergtsrz@gmail.com|LINK
I LOVE YOU! I spent many hours today trying to figure out why my update panels were not working with my ISAPI Rewrite site and this just solved it for me. Thank you very much!
None
0 Points
1 Post
Re: UpdatePanel posts back to wrong URL when URLMappings used in a "subdirectory"
Mar 31, 2009 04:06 AM|kenny.no|LINK
Thanks a million Jeffrey. I experienced this behavior when moving a working app from IIS7 to IIS6. After adding your script everything worked perfectly in IIS6 as well.
Cheers!
Kenneth
All-Star
48393 Points
12161 Posts
Re: UpdatePanel posts back to wrong URL when URLMappings used in a "subdirectory"
Mar 31, 2009 11:16 PM|chetan.sarode|LINK
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
Team Lead, Product Development
Approva Systems Pvt Ltd, Pune, India.
Member
2 Points
3 Posts
Re: UpdatePanel posts back to wrong URL when URLMappings used in a "subdirectory"
Jul 08, 2020 03:25 AM|eng_ahmed_taha|LINK
is this javascript or c#
and where i supposed to add ?