D
David
Hi all,
I am not quite sure how to phrase the subject, so apologies.
I am writing a custom control. It is using a textbox. I create the text box,
but cannot read the contents of it later.
Here is my code...
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing;
namespace MyProjectControls
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>")]
public class HTMLPlaceHolder : System.Web.UI.WebControls.WebControl
{
private System.Web.UI.WebControls.TextBox tb = new TextBox();
private string text;
private string _CurrentViewMode = "display";
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
public string CurrentViewMode
{
get
{
return _CurrentViewMode.ToLower();
}
set
{
_CurrentViewMode = value.ToLower();
}
}
/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
RenderContents(output);
}
protected override void OnPreRender(EventArgs e)
{
System.Web.UI.Page MyPage = this.Page as System.Web.UI.Page;
CurrentViewMode = MyPage.PageState;
Text = "This is purely test text"
if (MyPage.AllowSave)
{
SavePlaceholder();
}
switch (CurrentViewMode)
{
case "edit" :
AuthoringPlaceholder();
break;
case "display" :
DisplayPlaceholder();
break;
case "design" :
DesignPlaceholder();
break;
default:
DisplayPlaceholder();
break;
}
base.OnPreRender (e);
}
protected void DesignPlaceholder()
{
}
protected void AuthoringPlaceholder()
{
//TextBox tb = new TextBox();
//this.tb = new TextBox();
this.tb.ID = this.ID;
this.tb.TextMode = TextBoxMode.MultiLine;
this.tb.Text = Text;
this.tb.Columns = 40;
this.tb.Rows = 15;
Controls.Add(this.tb);
}
protected void DisplayPlaceholder()
{
LiteralControl lit = new LiteralControl("<div>" + Text + "</div>");
Controls.Add(lit);
}
protected void SavePlaceholder()
{
System.Web.HttpContext.Current.Response.Write(this.tb.Text);
}
}
}
In the SavePlaceHolder, I want to be able to display what is written in the
text box. (Actually, I want to save it, but to display it will show that
something is happening).
However, this.tb.Text has nothing in it in the SavePlaceholder.
How can I ensure that what is coming back when the page is submitted is
actually there?
Thanks.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
I am not quite sure how to phrase the subject, so apologies.
I am writing a custom control. It is using a textbox. I create the text box,
but cannot read the contents of it later.
Here is my code...
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.Drawing;
namespace MyProjectControls
{
/// <summary>
/// Summary description for WebCustomControl1.
/// </summary>
[DefaultProperty("Text"),
ToolboxData("<{0}:WebCustomControl1
runat=server></{0}:WebCustomControl1>")]
public class HTMLPlaceHolder : System.Web.UI.WebControls.WebControl
{
private System.Web.UI.WebControls.TextBox tb = new TextBox();
private string text;
private string _CurrentViewMode = "display";
[Bindable(true),
Category("Appearance"),
DefaultValue("")]
public string Text
{
get
{
return text;
}
set
{
text = value;
}
}
public string CurrentViewMode
{
get
{
return _CurrentViewMode.ToLower();
}
set
{
_CurrentViewMode = value.ToLower();
}
}
/// <summary>
/// Render this control to the output parameter specified.
/// </summary>
/// <param name="output"> The HTML writer to write out to </param>
protected override void Render(HtmlTextWriter output)
{
RenderContents(output);
}
protected override void OnPreRender(EventArgs e)
{
System.Web.UI.Page MyPage = this.Page as System.Web.UI.Page;
CurrentViewMode = MyPage.PageState;
Text = "This is purely test text"
if (MyPage.AllowSave)
{
SavePlaceholder();
}
switch (CurrentViewMode)
{
case "edit" :
AuthoringPlaceholder();
break;
case "display" :
DisplayPlaceholder();
break;
case "design" :
DesignPlaceholder();
break;
default:
DisplayPlaceholder();
break;
}
base.OnPreRender (e);
}
protected void DesignPlaceholder()
{
}
protected void AuthoringPlaceholder()
{
//TextBox tb = new TextBox();
//this.tb = new TextBox();
this.tb.ID = this.ID;
this.tb.TextMode = TextBoxMode.MultiLine;
this.tb.Text = Text;
this.tb.Columns = 40;
this.tb.Rows = 15;
Controls.Add(this.tb);
}
protected void DisplayPlaceholder()
{
LiteralControl lit = new LiteralControl("<div>" + Text + "</div>");
Controls.Add(lit);
}
protected void SavePlaceholder()
{
System.Web.HttpContext.Current.Response.Write(this.tb.Text);
}
}
}
In the SavePlaceHolder, I want to be able to display what is written in the
text box. (Actually, I want to save it, but to display it will show that
something is happening).
However, this.tb.Text has nothing in it in the SavePlaceholder.
How can I ensure that what is coming back when the page is submitted is
actually there?
Thanks.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available