views:

67

answers:

3

I am working on rewriting URLs Urlrewriting.net, and have run into what seems to be a common problem but I can seem to fix it. I'll present a simplified case.

The URL rewriting is working perfectly with the rule:

<urlrewritingnet rewriteOnlyVirtualUrls="true" defaultPage="default.aspx" defaultProvider="RegEx" xmlns="http://www.urlrewriting.net/schemas/config/2006/07"&gt;
   <rewrites>
       <add name="catalog" virtualUrl="^~/catalog/(.*)/(.*).aspx" rewriteUrlParameter="ExcludeFromClientQueryString" destinationUrl="~/catalog.aspx?cid=$1&amp;c=$2" ignoreCase="true"/>
   </rewrites>
</urlrewritingnet>

On the page I have a DataList with 2 asp:buttons inside. When clicked, the page refreshes but does nothing.

I followed ScottGu's article to impliment a form control adapter to rewrite the action of the form to match the rewritten URL.

Page URL in the browser: http://...../dev/catalog/13/Music.aspx

<form name="aspnetForm" method="post" action="/dev/catalog/13/Music.aspx" id="aspnetForm"> 

I now see the correct URL on the form action, and when debugging I can see the page load event firing.

The problem now is that every time the page loads Page.IsPostback is false, causing the page to rebind the DataList and therefore ignore the ItemCommand the buttons should be triggering.

if (!Page.IsPostBack)
     PopulateControls();

I'm using .NET 3.5 SP1, there is a ScriptManager on the master page but no UpdatePanel on this page. I've also tried resetting the Form.Action property and bypassing ScottGu's solution with the same result. If I go to the page URL directly without using the rewriter everything works fine.

What am I missing?

A: 

Persistence pays off. Turns out the problem was the following code on the master page:

<asp:LinkButton runat="server" PostBackUrl="~/basket.aspx" Text="View Cart" CausesValidation="false" />

I replaced that with a standard <a> tag and everything is working great.

NO IDEA why that would make a difference here. I guess when rewriting URLs any PostBackUrl or NavigateUrls will break the postbacks.

Sammy
A: 

It's the LinkButton problem, all the linkbutton should removed from the page include the master page.

peter
A: 

testing testing

Testing testing