views:

27

answers:

3

I have an odd problem. I have a page called search.aspx. When the search button is clicked, the user is supposed to be redirected to another website. The redirection code is in one of the postback events.

Here is the form code:

<form id="form1"  runat="server" onsubmit="return CheckSearchBox();"  action="http://mysearch.company.com/default.aspx" method="post" target="_top" > 

I have this same code deployed in two environments.

Working Environment

It has .NET 2.0 and 3.0, but no service packs. Here is how the source is rendered:

<form name="form1" method="post" action="search.aspx" id="form1" onsubmit="return CheckSearchBox();" target="_top">

Broken Environment

It has .NET 2.0 sp2 and 3.0 sp1. This is how the same code is rendered:

<form name="form1" method="post" action="http://mysearch.company.com/default.aspx" id="form1" onsubmit="return CheckSearchBox();" target="_top">

Notice that the rendered "action" is different. So, I have a few questions.

  • Why would ASP.NET change the action in one situation, but not the other?
  • Why would ASP.NET change the action at all?
  • Is there some sort of configuration I can make so that it always changes the action to "search.aspx"? (We haven't changed this code in years, and nobody wants to touch it.)
A: 

Hey,

I was always told that ASP.NET overwrote the action, not allowing you to control it at all. That's why they added the PostBackUrl property of the button, that when you clicked it it posted to another page....

So I'm surprised changing the action did work... but I don't know everything about the process :-)

HTH.

Brian
+1  A: 

Turns out that there was a change in .NET 2.0 SP2. Prior to that, ASP.NET just ignored whatever action you specified. But in .NET 2.0 SP2, it actually tries to use whatever is in the action. See the KB article here.

Jim
A: 

get rid of the runat="server"

matt-dot-net