Skip navigation links
Community
Events
Thought Leadership
Community Site
AIC CAM
Blogs

.NET 3.5 SP1 – Action Attribute in the Form 

Tags: Microsoft, Application Development and Integration

I was recently brought into a SharePoint project to help fix some bugs and generally be there as an extra resource while the team prepared for various “go live” dates.  One issue we were having was a failure to post form data to another web site for an automated login of sorts.  From within SharePoint, a link was created that would direct the user to an ASP.NET page, gather information and manipulate it from the user’s profile, determine which site the user wanted to go to and then submit the data to the site for an automatic login.  Easy enough, right?  Except it had one catch – when the “redirector” page submitted the form data to the site, it wouldn’t post to the target site.  Now, this problem occurred when the necessary files were deployed to the dev environment.  It worked very well on our individual development machines.  Why was this happening?

After some research, I found a couple articles here and here that outline an issue that is solved by installing .NET 3.5 SP1.  From my understanding, from .NET 1.1 through 3.5, if you put a URL value in the Action attribute of the ASP.NET form, the code was ignored by the framework and posted back to itself.  Unlike the days of classic ASP where you could define the POST event, .NET adopted the model of single post back.  This means that regardless of the URL you specify in the Action attribute of the form tag, the page will always post back to itself, rendering the Action attribute useless and dead.  You’d have to use the Response.Redirect method or the Server.Transfer method (under certain circumstances) to get to another page.  Unfortunately, this didn’t actually post the data in the form – it just redirected the user to the new page, without logging the user in.  (Server.Transfer would probably work if you were posting to a site on the same server, but in this case we were not.)

<form id="form1" runat="server" action="http://www.myurl.com"></form>

With the release and implementation of SP1 for .NET 3.5, this issue has been addressed.  You can now enter a URL to post to in the Action attribute and then use the submit() from within a RegisterStartupScript call to submit the form data to the target URL.

ScriptManager.RegisterStartupScript(this.Page,

this.Page.GetType(),

"myScript",

"document.forms.form1.submit();",

true);

So, if you ever have to post data to another web site for anything, this is an easy method.  Just make sure the server the code is running on has .NET 3.5 SP1 installed and you shouldn’t have the problem we did.

 
Posted by Deroeck, Gregory on 10-Apr-09
0 Comments  |  Link to this post  | Bookmark this post with:        
 

Comments

Name:
URL:
Email:
Comments:
 
RSS Feed Feed your read!
Archives
April 2009 (3)
May 2009 (2)
June 2009 (1)
August 2009 (1)
September 2009 (2)
November 2009 (1)
Tag Cloud