Library tutorials & articles
Implementing HTTP Handlers in ASP.NET
- Introduction
- Creating the Handler
- Handling PostBack
- Redirect, Transfer or Rewrite?
Handling PostBack
Now that we have our URL rewriting in place, it's time to do some real work.
Based on this section's title, you've probably figured out that you're going to
have some post-back issues (if you haven't already tested that out). The
problem with post-back is that, when rendered, the HtmlForm object
sets the action to the physical page name. Of course, this means that when you
submit the form, your true page is displayed. This is obviously less than ideal
for URL beautification. Not to mention it would most likely confuse your users.
Well, there are two solutions to consider.
First, you can add a simple script block to fix the problem. This is the easiest
solution, but there's one problem: if a user has scripting turned off (as if
that is ever the case, anyway), the fix will be nullified. But, in case you
still like this solution (I do), add this code to your Page class.
If you don't already, I'd suggest creating a base Page object for
all of your pages to implement. Then, add this code to the base Page
class. This allows you a good deal of extensibility as far as adding common
features easily.
Register Javascript
RegisterStartupScript( "PostBackFix",
"<script>document.forms[0].action='';</script>" );
Your second option is to extend the HtmlForm class. This is pretty
simple, as you will see below, but it comes with its own issues. The main
problem that I have with this solution is that you have to explicitly add the
extended HtmlForm object to replace the default HTML form tag. Not
that it is hard to do, but it can get tedious if you're creating (or
converting) a lot of pages.
Action-less HtmlForm Object
public class ActionlessForm : HtmlForm
{
protected override void RenderAttributes(HtmlTextWriter
writer)
{
Attributes.Add("enctype", Enctype);
Attributes.Add("id", ClientID);
Attributes.Add("method", Method);
Attributes.Add("name", Name);
Attributes.Add("target", Target);
Attributes.Render(writer);
}
}
Each method has it's own pros and cons. They're pretty simple to understand, so
the decision shouldn't be too hard. Honestly, you can implement the second
option through a base Page class, but that adds a lot more
complexity to your system then you're probably looking for. Explore your
options and be innovative.
Related articles
Related discussion
-
Gizmox Announces release of Visual WebGui SDK version 6.2.2
by Visual WebGui (0 replies)
-
Error 4 Make sure that the class defined in this code file matches the 'inherits' attribute, and that it extends the correct base class (e.g. Page or UserControl).
by lbargers (3 replies)
-
How to receive data in web server sending from GPRS modem
by AshokSingh (1 replies)
-
Working with frames in c# .net
by pulak2008 (0 replies)
-
Time Out Problem
by lorrainepetty (1 replies)
Related podcasts
-
CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly Media
CodeCast Episode 4: State of .NET, IE8, ASP.NET MVC, and O'Reilly MediaHosts Ken Levy and Markus Egger discuss the new State of .NET events, IE8, ASP.NET MVC, followed by an interview from PDC with two editors from O'Reilly Media. More on ASP.NET MVC can be found at http://asp.net/mvc. Interview...
Related jobs
-
Microsoft .Net Architect
in AMSTERDAM (€50K-€90K per annum) -
Microsoft Dynamics CRM Technical Consultant
in Netherlands (€50K-€90K per annum) -
.net developer
in Rijswijk (€2K-€4K per annum)
Events coming up
-
Dec
3
An afternoon of SQL Server Data Services and ASP.NET Dynamic Data
Bradford, United Kingdom
This event is in association with Black Marble. In the morning Black Marble will be presenting on Microsoft "Oslo": The Future of Enterprise Applications. To find out more about this please follow the link on the right.
I haven't touched this since .NET 1.1. And, with IIS7, I'd say there's a better approach. I'll probably revisit this when I have some time to play with IIS7.
Did you ever find a better solution for the ActionLess form - for Url Rewriting ???
Your post to experts exchange requires a subscriptin to read the answer...
Cant I just get away with in NET 2.0 putting form id='myForm' Method=""
I know it is malformed ...
You seem to have forgotten an important problem with your actionless form. I have discovered that this custom form will disable the validation controls. Now the onsubmit function for client side validation needs to be added back in. I found this post about the problem (http://www.experts-exchange.com/Web/Q_21842631.html), but am still wondering if there is not an easier way to fix this.
thank you very much. I am knew this posting and waiting for nothoing
This thread is for discussions of Implementing HTTP Handlers in ASP.NET.