开发者

Build ASP.net headered control

开发者 https://www.devze.com 2022-12-19 23:31 出处:网络
Currently I\'m working on a extensive form, which I\'d like to organise by grouping input fields in groupbox-like panels. These panels have an header, a minimize and pin icon. Also inner controls shou

Currently I'm working on a extensive form, which I'd like to organise by grouping input fields in groupbox-like panels. These panels have an header, a minimize and pin icon. Also inner controls should be able to perform two-way binding to the FormViews datasource.

I can't find any builtin asp.net 开发者_如何转开发control that does the job. What is the best way to accomplish this feature request? Any examples available on this (can't find a decent one)?

Many thanks!


Templated controls will get the job done. Check out these links for more information:

  • http://msdn.microsoft.com/en-us/library/aa478964.aspx
  • http://weblogs.asp.net/palermo4/archive/2007/01/10/creating-a-custom-databound-templated-control-in-asp-net-2-0.aspx


Tuturials are interesting, but didn't realy need templated controls at the moment, neither databound controls. Only controls in the controlcollection should be able to do so, but apparently they're able by default.

Found out multiple ways to accomplish. One to extend the default Panel control, the other one to extend from WebControl as shown below. Works as intended.

[DefaultProperty("HeaderText")]
[ToolboxData(@"<{0}:FormGroupBox runat=""server"" HeaderText=""Title""></{0}:FormGroupBox>")]
[PersistChildren(true), ParseChildren(false, "Controls")]
public class FormGroupBox : WebControl
{
    [Bindable(true)]
    [Category("Appearance")]
    [DefaultValue("")]
    [Localizable(true)]
    public string HeaderText
    {
        get
        {
            String s = (String) ViewState["HeaderText"];
            return ((s == null) ? "[" + this.ID + "]" : s);
        }

        set
        {
            ViewState["HeaderText"] = value;
        }
    }

    protected override void RenderContents(HtmlTextWriter output)
    {
        output.Write(string.Format("<strong>{0}</strong>", this.HeaderText));
        output.Write(@"<hr />");

        base.RenderContents(output);
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号