This is a small article which describes small code snippet which can be used to get access to the Html Form Control of an Aspx Page.
Given below is code for a class by name BasePage.
System;using
using
System.Collections;using
System.ComponentModel;using
System.Data;using
System.Drawing;using
System.Web;using
System.Web.SessionState;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.HtmlControls;namespace
HandlerTest{
public class BasePage:Page{
private HtmlForm _pageform = null; protected HtmlForm PageForm{
get{
return _pageform;}
}
protected override void AddedControl(Control control, int index){
if(control is HtmlForm){
_pageform = control
as HtmlForm;}
base.AddedControl (control, index);}
protected bool HasForm{
get{
return (_pageform != null);}
}
}
}
This class is derived from the Page class of System.Web.UI.WebControls namespace.
Here we are overiding the AddedControl method of the base class and verfying if the control being added is a HtmlForm control and if it is then we are assigning the control to the _pageform variable.
Also the property PageForm allows us to access the Form Control from any class derived from the BasePage Class.
lodPosted Mar 31, 2006, 2:52 AM
Yes, I see the idea... But I bet it would have been easier to read the code if it was made a bit more readable... At least I prefere if the code is properly indented... And that "using" statements that are not used anyway, are removed, it make it easier to see what it is working with... And some comment (You know, lines starting with //) describing the thoughts behind the code, is nice to have...