Guest User

Untitled

a guest
Jul 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.98 KB | None | 0 0
  1. using System;
  2. using System.Collections.Specialized;
  3. using System.ComponentModel;
  4. using System.Text;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.HtmlControls;
  9. using System.Collections;
  10.  
  11.  
  12. namespace CustomWebControl
  13. {
  14. [DefaultProperty("Text")]
  15. [ToolboxData("<{0}:ServerControl1 runat=server></{0}:ServerControl1>")]
  16. public class CustomTextBox : WebControl
  17. {
  18. private HtmlGenericControl SPAN;
  19. protected TextBox _txtBox;
  20.  
  21.  
  22. public string GetText
  23. {
  24. get
  25. {
  26. return _txtBox.Text;
  27. }
  28. }
  29. protected override object SaveViewState()
  30. {
  31. object[] basestate = new object[2];
  32. basestate[0] = base.SaveViewState();
  33. basestate[1] = _txtBox.Text;
  34. return basestate;
  35. }
  36.  
  37. protected override void LoadViewState(object savedState)
  38. {
  39. if (savedState != null)
  40. {
  41. object[] state = (object[])savedState;
  42. base.LoadViewState(state[0]);
  43. if (state.Length > 1)
  44. {
  45. if (state[1] != null)
  46. {
  47. _txtBox.Text = state[1].ToString();
  48. }
  49. }
  50. }
  51. }
  52.  
  53. public CustomTextBox()
  54. {
  55. SPAN = new HtmlGenericControl("span");
  56. _txtBox = new TextBox();
  57. _txtBox.EnableViewState = true;
  58. }
  59.  
  60. protected override void RenderContents(HtmlTextWriter output)
  61. {
  62.  
  63. _txtBox.ID = this.UniqueID + "_TXT";
  64. SPAN.Controls.Add(_txtBox);
  65.  
  66. SPAN.RenderControl(output);
  67. }
  68.  
  69. public bool LoadPostData(string postDataKey, NameValueCollection postCollection)
  70. {
  71. this._txtBox.Text = postCollection[postDataKey + "_TXT"];
  72.  
  73. return true;
  74. }
  75. }
  76. }
Add Comment
Please, Sign In to add comment