Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Specialized;
- using System.ComponentModel;
- using System.Text;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- using System.Web.UI.HtmlControls;
- using System.Collections;
- namespace CustomWebControl
- {
- [DefaultProperty("Text")]
- [ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")]
- public class CustomTextBox : WebControl
- {
- private HtmlGenericControl SPAN;
- protected TextBox _txtBox;
- public string GetText
- {
- get
- {
- return _txtBox.Text;
- }
- }
- protected override object SaveViewState()
- {
- object[] basestate = new object[2];
- basestate[0] = base.SaveViewState();
- basestate[1] = _txtBox.Text;
- return basestate;
- }
- protected override void LoadViewState(object savedState)
- {
- if (savedState != null)
- {
- object[] state = (object[])savedState;
- base.LoadViewState(state[0]);
- if (state.Length > 1)
- {
- if (state[1] != null)
- {
- _txtBox.Text = state[1].ToString();
- }
- }
- }
- }
- public CustomTextBox()
- {
- SPAN = new HtmlGenericControl("span");
- _txtBox = new TextBox();
- _txtBox.EnableViewState = true;
- }
- protected override void RenderContents(HtmlTextWriter output)
- {
- _txtBox.ID = this.UniqueID + "_TXT";
- SPAN.Controls.Add(_txtBox);
- SPAN.RenderControl(output);
- }
- public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
- {
- this._txtBox.Text = postCollection[postDataKey + "_TXT"];
- return true;
- }
- }
- }
Add Comment
Please, Sign In to add comment