using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq;using System.Text; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; using System.Reflection; namespace DNWebComponent { [DefaultProperty("Text")] [ToolboxData("<{0}:DNTextBox runat=server></{0}:DNTextBox>")] public class DNTextBox : WebControl, IDNComponent { public String _ConnectedField; private string _label; private TextBox _txtBox; private string _connectedField; private string _MultiSeekField; private string _InputTable; public string ControlClientID; public DNTextBox() { _txtBox = new TextBox(); } [PersistToViewState] [Bindable(true)] [Category("Appearance")] [DefaultValue("")] [Localizable(true)] public string Text { get { String s = (String)ViewState["Text"]; return ((s == null) ? "[" + AspTextBox.Text + "]" : s); } set { ViewState["Text"] = value; } } public DNTextBox(string label) : this() { this._label = label; } public String Label { get { return _label; } set { _label = value; } } public String ConnectedField { get { return _connectedField; } set { _connectedField = value; } } public String MultiSeekField { get { return _MultiSeekField; } set { _MultiSeekField = value; } } public String InputTable { get { return _InputTable; } set { _InputTable = value; } } public TextBox AspTextBox { get { return _txtBox; } set { _txtBox = value; } } public string DivCss { get; set; } protected override void RenderContents(HtmlTextWriter output) { output.Write("<div class=\"" + DivCss + "\" >"); output.Write(Text); output.Write(_label + ": "); _txtBox.RenderControl(output); output.Write("</div>"); } public bool FillControl() { return false; } protected override void LoadViewState(object savedState) { base.LoadViewState(savedState); PropertyInfo[] properties = GetType().GetProperties(); foreach (PropertyInfo property in properties) { object[] attributes = property.GetCustomAttributes(typeof(PersistToViewState), true); if (attributes.Length > 0) { if (ViewState[property.Name] != null) property.SetValue(this, ViewState[property.Name], null); } } } protected override object SaveViewState() { ViewState["Text"] = AspTextBox.Text; //PropertyInfo[] properties = GetType().GetProperties(); //foreach (PropertyInfo property in properties) { // object[] attributes = property.GetCustomAttributes(typeof(PersistToViewState), true); // if (attributes.Length > 0) // ViewState[property.Name] = property.GetValue(this, null); //} return base.SaveViewState(); } [AttributeUsage(AttributeTargets.Property)] public class PersistToViewState : Attribute { } } }
public DNTextBox() { _txtBox = new TextBox(); this.Controls.Add(_txtBox); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)