|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionOne of the most common hitches that ASP developers encounter when they first approach ASP.NET is that managed Web applications must be written according to a single-form interface model. In the single form interface model, each page always posts to itself by default using the POST HTTP method. The HTTP method and the target frame of the post can be programmatically adjusted using ad hoc form properties— Following is the description found on MSDN regarding the limitation.
This article is to illustrate the limitation of the ASP.NET Let’s consider a situation where either:
We cannot fulfill the above requisites in currently available UI related controls in ASP.NET. This article is concentrating on the aspects of providing the For live demo of this submission, navigate to Live Demo site. Background (HtmlForm class: reviewed)In HTML and ASP programming, the form element (i.e., Before going into further detail, let's take a little review on CHtmlForm: a more powerful shape of HtmlForm for ASP.NETWhile we reviewed Let us start the process of customization of The /// <summary>
/// purpose: Overridden to render custom Action attribute
/// The main purpose of the Overridding is to grab the
/// "action" attribute of the original
/// form
/// </summary>
protected override void RenderAttributes(System.Web.UI.HtmlTextWriter writer) {
// Prepare our own action , method and name
writer.WriteAttribute("name", this.Name);
writer.WriteAttribute("method", this.Method);
writer.WriteAttribute("action", this.ResolveUrl(this.Action), true);
// Remove From HtmlForm, with changes to Action
this.Attributes.Remove("name");
this.Attributes.Remove("method");
this.Attributes.Remove("action");
string submitEvent = this.Page_ClientOnSubmitEvent;
// Now check the onsubmit event associated with Htmlform
if (submitEvent != null && submitEvent.Length > 0) {
// ok.. this for has a "OnSubmit"
if (this.Attributes["onsubmit"] != null) {
submitEvent = submitEvent + this.Attributes["onsubmit"];
this.Attributes.Remove("onsubmit");
}
//Add some new Attributes to make the new form little more rich
writer.WriteAttribute("language", "javascript");
writer.WriteAttribute("onsubmit", submitEvent);
}
writer.WriteAttribute("id", this.ClientID);
// following is meant for HtmlContainerControl
this.ViewState.Remove("innerhtml");
// following is meant for HtmlControl
this.Attributes.Render(writer);
}
// The above code shows the overriden method RenderAttribute(writer)private Object GetHideProperty(Object target,
Type targetType, String propertyName )
{
PropertyInfo property = targetType.GetProperty(propertyName,
BindingFlags.IgnoreCase |
BindingFlags.Instance | BindingFlags.NonPublic );
if ( property != null ) {return property.GetValue(target, null);}
else {return null; }
}
/// The above code shows the GetHideProperty which uses reflection
/// to access any property on an object, even though the property
/// is marked protected, internal, or private.
Points of InterestFollowing code snippet shows how the final structure of a page will look like: <%@ Register TagPrefix="dtform" Namespace="DerivedTool.WebControls"
Assembly="DerivedTool.WebControls.HtmlForm" %>
<dtform:CHtmlForm Action="some_other_page.aspx" runat="server">
<asp:TextBox id="symbols" runat="server" value=></asp:TextBox>
<asp:Button runat="server" Text="check Quote" />
</dtform:CHtmlForm>
If you want to PostBack to the same ASP.NET page, just leave How to deploy CHtmlFormThough deployment of this server–side control is very easy and simple, I am providing following steps to test the control with ASP.NET.
Enjoy!
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||