HTML Postback Custom Control
Web form controls do not offer a complete solution to ASP.Net design and hence
HTML tags are still required. Occasionally the need exists for an a postback
from an HTML tag, this article presents a Custom Control to address this requirement.
When using Map and Area tags, for instance, on a ASP.NET Web Form performing
a postback to redirect the user to a new page is often needed. This can be
addressed by using a User Control Hints
and Tips or in the case of ASP.NET 2.0 new classes are available
to address this requirement Server
Event Handling in ASP.NET Web Pages. With ASP.NET 1.1 these classes are
not available and using a Custom Control provides a very simple
and compact solution.
The control consists of two elements; event handler, output render.
handler is standard "Click/Onclick" event code which also includes a
to notify the control that it should handle
an incoming postback event. This method extracts the event argument and
saves it within the property variable
htmlStr thereby enabling
your code behind event method to read, test and take the appropriate action.
The render method outputs an anchor tag with no content text. Using the anchor
tag ensures the inclusion of the
while not having any content text between the tag pair means the anchor will
not activate. The
__doPostBack function can be called by any HTML
tag using an
onclick attribute and passing the custom control
HtmlPostback1, as the event target and a user specified
string as the event argument.
Using the code
The above screen shot shows a simple test application of the Custom Control
using a div tag to generate a postback and is included as part of the download
code. The HtmlPostback Custom Control is dragged onto the web form, then as
by the required HTML tag.
A link is required between Custom Control event property
the code behind event method. The test application code behind method
the argument string, ensures it is valid and then writes it to
Point of Interest
As indicated above this is a very simple Custom Control with very few lines
of code. The interest and novelty is in the application which is described