This is a migrated thread and some comments may be shown as answers.

problem in renderening text in tabs at runtime

2 Answers 25 Views
TabStrip
This is a migrated thread and some comments may be shown as answers.
Hiren
Top achievements
Rank 1
Hiren asked on 02 Jun 2011, 10:52 AM
I am generating tabs at runtime with close button for each tab,  when i select any item from dropdown then it generating tab with close button but without text, check the attached image. when i select another item from dropdown it adding text to already generated tab, but for the tab which is generated last not showing the text, how to solve the issue..

aspx.cs page
protected override void OnInit(EventArgs e)
 {
       RadTabStrip1.TabTemplate = new TabTemplate();
       base.OnInit(e);
 }
 protected void Page_Load(object sender, EventArgs e)
 {
       if (!Page.IsPostBack)
            BindUsers();
       RadTabStrip1.DataBind();
 }
 
 private void BindUsers()
{
 .  .. . . . .
}
protected void ddlUsers_SelectedIndexChanged(object sender, EventArgs e)
{
     if (ddlUsers.SelectedIndex != 0)
     {
          if (RadTabStrip1.Tabs.Count == 0)
          {
              RadTab Separator = new RadTab();
              Separator.IsSeparator = true;
              Separator.Width = Unit.Pixel(50);
              RadTabStrip1.Tabs.Add(Separator);
              RadTab tab1 = new RadTab(ddlUsers.SelectedItem.Text, ddlUsers.SelectedItem.Value);
              RadTabStrip1.Tabs.Add(tab1);
              RadTabStrip1.Tabs.FindTabByText(ddlUsers.SelectedItem.Text).Selected = true;
         }
        else if (RadTabStrip1.Tabs.Count > 0 && RadTabStrip1.FindTabByText(ddlUsers.SelectedItem.Text) == null)
        {
                    //RadTab Separator = new RadTab();
                    //Separator.IsSeparator = true;
                    //Separator.Width = Unit.Pixel(5);
                    //RadTabStrip1.Tabs.Add(Separator);
 
              RadTab tab1 = new RadTab(ddlUsers.SelectedItem.Text, ddlUsers.SelectedItem.Value);
              RadTabStrip1.Tabs.Add(tab1);
              RadTabStrip1.Tabs.FindTabByText(ddlUsers.SelectedItem.Text).Selected = true;
         }
        else
             RadTabStrip1.Tabs.FindTabByText(ddlUsers.SelectedItem.Text).Selected = true;
             GetDashboards(ddlUsers.SelectedItem.Text);
       }
      else
       {
           ddlDashboards.Items.Clear();
           ddlDashboards.DataSource = CreateEmptyDataTable();
           ddlDashboards.DataTextField = "DashboardTitle";
           ddlDashboards.DataValueField = "DashboardKey";
           ddlDashboards.DataBind();
       }
}

class file
class TabTemplate : ITemplate
    {
        public void InstantiateIn(Control container)
        {
            Label lbl = new Label();
            lbl.ID = "ItemLabel";
            //lbl.Text = "";
            lbl.DataBinding += new EventHandler(lbl_DataBinding);
            ImageButton ImgBtnClose = new ImageButton()
            {
                ImageUrl = "../../Images/delete1.gif",
                CssClass = "image"
            };
            ImgBtnClose.Click += new ImageClickEventHandler(ImgBtnClose_Click);
            ImgBtnClose.Attributes.Add("onclick", "return confirm('Do you want to close this tab.');");
            container.Controls.Add(lbl);
            container.Controls.Add(ImgBtnClose);
        }
 
        void ImgBtnClose_Click(object sender, ImageClickEventArgs e)
        {
            ImageButton target = (ImageButton)sender;
            RadTab tab = (RadTab)target.BindingContainer;
            RadTabStrip tabStrip = (RadTabStrip)tab.Parent;
            tabStrip.Tabs.Remove(tab);
        }
 
        private void lbl_DataBinding(object sender, EventArgs e)
        {
            Label target = (Label)sender;
            RadTab tab = (RadTab)target.BindingContainer;
            string tabText = (string)DataBinder.Eval(tab, "Text");
            target.Text = tabText;
        }
    }

2 Answers, 1 is accepted

Sort by
0
Kate
Telerik team
answered on 08 Jun 2011, 08:36 AM
Hello Giri,

I tried to run the code that you provided but with no success. Can you please open a support ticket and send us a runnable project containing only the minimum requirements to be able to see the issue, so we can help you out?

Regards,
Kate
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Hiren
Top achievements
Rank 1
answered on 08 Jun 2011, 12:37 PM
Thanks for replying, i had resolved the issue
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {       }
        BindTabStripCloseButton();
    }
 
    private void BindTabStripCloseButton()
    {
        TextBoxTemplate template = new TextBoxTemplate();
        foreach (RadTab tab in RadTabStrip1.GetAllTabs())
        {
            template.InstantiateIn(tab);
        }
        RadTabStrip1.DataBind();
    }
    protected void ddlUsers_SelectedIndexChanged(object sender, EventArgs e)
        {
               if (RadTabStrip1.Tabs.Count == 0)
                {
                    //RadTab Separator = new RadTab();
                    //Separator.IsSeparator = true;
                    //Separator.Width = Unit.Pixel(50);
                    //RadTabStrip1.Tabs.Add(Separator);
 
                    RadTab tab1 = new RadTab(ddlUsers.SelectedItem.Text, ddlUsersSelectedItem.Value);
                    RadTabStrip1.Tabs.Add(tab1);
                    RadTabStrip1.Tabs.FindTabByText(ddlUsers.SelectedItem.Text).Selected = true;
                }
                else if (RadTabStrip1.Tabs.Count > 0 && RadTabStrip1.FindTabByText(ddlUsers.SelectedItem.Text) == null)
                {
                    //RadTab Separator = new RadTab();
                    //Separator.IsSeparator = true;
                    //Separator.Width = Unit.Pixel(5);
                    //RadTabStrip1.Tabs.Add(Separator);
 
                    RadTab tab1 = new RadTab(ddlUsers.SelectedItem.Text,ddlUsers.SelectedItem.Value);
                    RadTabStrip1.Tabs.Add(tab1);
                    RadTabStrip1.Tabs.FindTabByText(ddlUsers.SelectedItem.Text).Selected = true;
                    TabTemplate tbTemplate = new TabTemplate();
                    tbTemplate.InstantiateIn(tab1);
                    RadTabStrip1.DataBind();
                }
                else
                    RadTabStrip1.Tabs.FindTabByText(ddlUsers.SelectedItem.Text).Selected = true;
        }
}
 
class TextBoxTemplate : ITemplate
{
    public void InstantiateIn(Control container)
    {
        Label lbl = new Label();
        lbl.DataBinding += new EventHandler(lbl_DataBinding);
        ImageButton ImgbtnClose = new ImageButton()
        {
            ImageUrl = "Images/close_selected.png",
            CssClass = "image"
        };
        ImgbtnClose.Click += new ImageClickEventHandler(btnClose_Click);
        ImgbtnClose.Attributes.Add("onmouseover", "this.src='Images/close_hover.png'");
        ImgbtnClose.Attributes.Add("onclick", "return confirm('Do you want to close this tab.');");
        container.Controls.Add(lbl);
        container.Controls.Add(ImgbtnClose);
    }
 
    void btnClose_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton target = sender as ImageButton;
        RadTab tab = target.BindingContainer as RadTab;
        RadTabStrip tabStrip = tab.Parent as RadTabStrip;
        tabStrip.Tabs.Remove(tab);
    }
 
    private void lbl_DataBinding(object sender, EventArgs e)
    {
        Label target = (Label)sender;
        RadTab tab = (RadTab)target.BindingContainer;
        string tabText = (string)DataBinder.Eval(tab, "Text");
        target.Text = tabText;
    }
}
Tags
TabStrip
Asked by
Hiren
Top achievements
Rank 1
Answers by
Kate
Telerik team
Hiren
Top achievements
Rank 1
Share this question
or