Hi,
Thank you both (tdotnet and Michael), however I am still having problems...
It may be a combination of both answers.
I have written an OnInit
protected override void OnInit(EventArgs e)
{
//tb.ID = this.ID;
tb.TextMode = TextBoxMode.MultiLine;
//this.tb.Text = Text;
tb.Columns = 40;
tb.Rows = 15;
Controls.Add(tb);
base.OnInit (e);
}
(Note, the Text property has been remarked, as that can only really be
loaded in the OnPreRender).
This seems to prepare the textbox but on the postback, when I am trying to
read it, there is nothing. How do I ensure that there is text in the
postback?
(I pre-load the text box in pre-render, I wish to be able to change the
contents and I want to see what is in the text boxes when it comes back)
I have never used the IPostBackDataHandler. Given what I have written above,
does it look like this is what I need? If so, can you show me an example?
Thanks.
Best regards,
Dave Colliver.
http://www.AshfieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
>I think the problem you have is that you're not loading the contents of
> the control tree properly. I don't think .NET can find the Textbox
[quoted text clipped - 10 lines]
> setting the text property of the Textbox by implementing the
> IPostBackDataHandler interface.
David - 29 Oct 2006 22:10 GMT
Hi,
Sorted it. A combination of OnInit and IPostBackDataHandler (which gave me a
few headaches to make work...).
It seems that IPostBackDataHandler needs to return a boolean value. What is
this for?
Best regards,
Dave Colliver.
http://www.SheffieldFOCUS.com
~~
http://www.FOCUSPortals.com - Local franchises available
> Hi,
>
[quoted text clipped - 51 lines]
>> setting the text property of the Textbox by implementing the
>> IPostBackDataHandler interface.
Michael Hamrah - 30 Oct 2006 17:14 GMT
The IPostBackDataHandler returns a boolean value if the data has
changed in the control. THis is so it can raise a data changed event.
I wrote the following code below which doesn't use the
IPostBackDataHandler (it relies on the textbox data handler, but it may
not fit your needs in the long run.
Anyway, the trick is to leverage the CreateChildControls function.
This function gets called anytime .NET needs the control to be in a
valid state- essentially during a postback after the init event and
before it gets rendered.
public class HTMLPlaceholder : CompositeControl
{
private TextBox tb = new TextBox();
private string _text;
private string _viewMode;
public string ViewMode
{
get { return (ViewState["ViewMode"] == null) ? "default" :
ViewState["ViewMode"].ToString(); }
set { ViewState["ViewMode"] = value; }
}
public string Text
{
get { return _text; }
set { _text = value; }
}
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
}
protected override void OnLoad(EventArgs e)
{
this.Text = tb.Text;
base.OnLoad(e);
}
protected override void OnPreRender(EventArgs e)
{
CreateChildControls();
base.OnPreRender(e);
}
protected override void CreateChildControls()
{
Controls.Clear();
switch (ViewMode)
{
case "Edit":
AuthoringPlaceholder();
break;
case "default":
TextPlaceHolder();
break;
}
base.CreateChildControls();
}
protected void AuthoringPlaceholder()
{
tb = new TextBox();
this.tb.ID = this.ID;
this.tb.TextMode = TextBoxMode.MultiLine;
//this.tb.Text = Text; Don't need to set this
this.tb.Columns = 40;
this.tb.Rows = 15;
Controls.Add(this.tb);
}
protected void TextPlaceHolder()
{
this.Controls.Add(new LiteralControl(this.Text));
}
}
In your page class you can switch modes like this:
protected void Page_Load(object sender, EventArgs e)
{
if (this.IsPostBack)
{
test.ViewMode = "default";
}
}
And place it in the page like this:
<cc1:HTMLPlaceholder runat=server ViewMode="Edit" id="test" />
<asp:Button runat="server" ID="submit" Text="submit" />
> Hi,
>
[quoted text clipped - 65 lines]
> >> setting the text property of the Textbox by implementing the
> >> IPostBackDataHandler interface.