The HtmlForm class under System. Web. UI. HtmlControls is tested, which is the Form object we use in traditional asp.net. It is not suitable for generating Html code dynamically.
Therefore, a simple HtmlForm container control is customized, which requires only a few lines of code. It seems that Asp.net is still very advantageous in encapsulating Html elements. Microsoft has defined
A large number of basic structures are easy to expand and use.
public class myHtmlForm:HtmlContainerControl
{
public myHtmlForm()
: base("form")
{
this.Attributes.Add("method", "post");
}
public string Action
{
set
{
Attributes.Add("action", value);
}
}
}
It's easy to use. Just add a new control to the Controls set.
myHtmlForm form = new myHtmlForm();
form.ID = "myform";
form.Action = "test.aspx";
HtmlInputHidden hidf= new HtmlInputHidden();
hidf.ID = hidf.Name = "hidden";
form.Controls.Add(hidf);
Finally, the HTML code is output to the response stream in the View.
form.RendControl(Writer);
Conclusion:
Dynamic generation of HTML forms is so simple and clear. I used to splice HTML and Write it myself. Classes provided by the framework can effectively improve the opening efficiency,
Make the code readable. It is helpful to make good use of the System. Web. UI. WebControls. Table control, especially when using Table controls. I 'd like to know about PHP or other
Does the language have these useful infrastructure?