locked
How to Check If An Ajax Tab Is Empty Using C# RRS feed

  • Question

  • User-471962099 posted

    hi all,

    I want to check whether the ajax tab is empty, if there is nothing inside the ajax tab, I want to display "no content found" label message. My ajax tab is being populated dynamically in C# in this way:

     public void BindChart()
            {
                //Create new TabContainer
                AjaxControlToolkit.TabContainer container = new AjaxControlToolkit.TabContainer();
                container.ID = "TabContainer";
                container.EnableViewState = false;
                container.Tabs.Clear();
    
                        AjaxControlToolkit.TabPanel panel = new AjaxControlToolkit.TabPanel();
                        panel.HeaderText += item.Text;
                        container.Tabs.Add(panel);

    Question: How to check if any ajax tab is empty/has no content then add in a label in that empty tab?

    Thanks.

    Tuesday, October 27, 2015 11:54 PM

Answers

  • User1724605321 posted

    Hi Felicia Tan,

    Since your ajax tab is created dynamically in code behind , i would suggest you could add the "no content found" label message when you create the tabs . If you have not set any content to the ajax tabPanel ,then you could add the message like :

                        if(//you don't want to add control to panel)
                        {
                           Label tabContent = new Label();
                           tabContent.Text += "no content found";
                        }

    Then add to the tab panel by :

                        AjaxControlToolkit.TabPanel panel = new AjaxControlToolkit.TabPanel();
                        panel.HeaderText += item.Text;
                        container.Tabs.Add(panel);
                        panel.Controls.Add(tabContent);

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 28, 2015 3:22 AM

All replies

  • User1724605321 posted

    Hi Felicia Tan,

    Since your ajax tab is created dynamically in code behind , i would suggest you could add the "no content found" label message when you create the tabs . If you have not set any content to the ajax tabPanel ,then you could add the message like :

                        if(//you don't want to add control to panel)
                        {
                           Label tabContent = new Label();
                           tabContent.Text += "no content found";
                        }

    Then add to the tab panel by :

                        AjaxControlToolkit.TabPanel panel = new AjaxControlToolkit.TabPanel();
                        panel.HeaderText += item.Text;
                        container.Tabs.Add(panel);
                        panel.Controls.Add(tabContent);

    Best Regards,

    Nan Yu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 28, 2015 3:22 AM
  • User-471962099 posted

    hi Nan Yu, thanks for your reply and help! I have solved this using the following code:

     if(panel.Controls.Count<1)
                        {
                            System.Web.UI.HtmlControls.HtmlGenericControl panelDIV = new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
                            panelDIV.ID = "panelDIV";
                            panelDIV.Style.Add(HtmlTextWriterStyle.TextAlign, "center");
                            panelDIV.Style.Add(HtmlTextWriterStyle.Width, "100%");
    
                            System.Web.UI.WebControls.Label newTabel = new System.Web.UI.WebControls.Label();
                            newTabel.Text += "<br />" + "<br />" + "<br />" + "<br />" + "no data to display";
                            newTabel.Font.Bold = true;
                            newTabel.Font.Size=16;
                            panelDIV.Controls.Add(newTabel);
                            panel.Controls.Add(panelDIV);
                        }

    Thanks.

    Wednesday, October 28, 2015 9:57 AM