Welcome Guest Search | Active Topics | Sign In | Register

Dynamically Creating a Control With Tool Tip Options
PDG
Posted: Tuesday, December 17, 2013 5:30:54 PM
Rank: Advanced Member
Groups: Member

Joined: 12/19/2010
Posts: 47
Is there any sample code to do this? I create my controls dynamically and would like to optionally have the user add a tool tip. My users create their controls by dragging them onto a palette and then defining them. How can I dynamically create a tooltip for the dynamically created control. Any sample code would be appreciated.

In page_load, programatically:
1. Create control (simple textbox);
2. Add Tooltip to control.

Thanks in advance ...
PDG
Posted: Wednesday, December 18, 2013 8:49:32 AM
Rank: Advanced Member
Groups: Member

Joined: 12/19/2010
Posts: 47
This must be done with the EO.Web.ToolTip object using an ITemplate that instantiates in a label control. Assuming that TextBox control was created with the ID: tb_stname and a PlaceHolder exists on the page with the ID: ph_stname here is how the tooltip is created dynamically:

EO.Web.ToolTip tt = new EO.Web.ToolTip();
tt.ID = string.Format("tt_stname");
tt.For = "tb_stname";
tt.ContentTemplate = new ToolTipTemplate("Hello, here is the tooltip text");
ph_stname.Controls.Add(tt);

Here is the ToolTipTemplate class:

public class ToolTipTemplate : ITemplate
{
private string txt;

// *** Constructor used to pass string to label control
public ToolTipTemplate(string txt)
{
this.txt = txt;
}

// *** Instantiates ITemplate with Label
public void InstantiateIn(System.Web.UI.Control container)
{
Label la = new Label();
la.ID = "Ffff";
la.Text = txt;
container.Controls.Add(la);
}
}
PDG
Posted: Wednesday, December 18, 2013 9:02:56 AM
Rank: Advanced Member
Groups: Member

Joined: 12/19/2010
Posts: 47
There is a much easier way to do this without having to use an ITemplate. You can also use the BodyHtml and HeaderHtml attributes.
eo_support
Posted: Wednesday, December 18, 2013 1:50:52 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

Thanks for the updates and sharing. Dynamically creating a control is generic ASP.NET topic so there really isn't anything particular related to our controls. So you may want to search online on that topic and as you have noted, there are issues like ITemplate that may require additional code. In addition to that, you also must pay attention to the control's life cycle. There are two general rules:

1. The control must be created as early as possible. Some controls won't work well if it is added into the page too late --- an extremely example is if you create the control after the page has already been rendered, then obviously it has no effect;
2. If you need event from the control, you must create the control during the initial load (when Page.IsPostBack is false) and during the post back (when Page.IsPostBack is true) exactly the same way. In another word, you must re-create the control during post back. This is essential for server side event to fire properly;

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.