Click here to Skip to main content
15,917,862 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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:
C#
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?

I have solved it but anyone knows label font style to Arial in C#?
This is my updated code:
C#
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 content to display";
                       newTabel.Font.Bold = true;
                       newTabel.Font.Size=16;
                       panelDIV.Controls.Add(newTabel);
                       panel.Controls.Add(panelDIV);
                   }


Thanks.
Posted
Updated 28-Oct-15 4:27am
v3
Comments
Richard Deeming 28-Oct-15 11:08am    
Once you have a solution to your question, don't update the question with a new, unrelated question.

Post your new question as a new question, and leave the original question alone.

1 solution

You can use several process like
C#
 if (panel.Controls.Count > 0)
{
   // Add A lable
}

or
C#
if (panel.HasControls())
{
    // Add A lable
}

or
C#
StringBuilder content = new StringBuilder();
StringWriter sWriter = new StringWriter(content);
HtmlTextWriter htmlWriter = new HtmlTextWriter(sWriter);
pnlMyPanel.RenderControl(htmlWriter);

if (htmlWriter.ToString() != "")
{
    // Add A lable
}
 
Share this answer
 
Comments
Member 11999641 28-Oct-15 9:55am    
hi Debojyoti Saha, thanks for your reply, have solved my issue! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900