Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

i want to get anchor tag id which is now a by below code i am able to get parent li id but i need anchor tag id under that
  • from my code i want to get "M_Ho_1",M_Ho_2 etc

    Pls help me

    Thanks
    Pravanjan

    What I have tried:

    <li class="has-sub" id="li_M_Hosp" runat="server"><a href="#" id="M_Hosp" runat="server">
    Hospital

    • <a id="M_Ho_1" runat="server" href="/KB/answers/HospitalCreation.aspx">Hospital Creation
    • <a id="M_Ho_2" runat="server" href="/KB/answers/HospitalRegisteredHCP.aspx">HCP
    • <a id="M_Ho_3" runat="server" href="/KB/answers/Hospital_HCPApproval.aspx">HCP Approval

  • C#
    string menus= ",M_Hosp,M_Ho_1,";
    M_Home.Visible = menus.Contains("," + M_Home.ID + ",") ? true : false;


    C#
    foreach (System.Web.UI.HtmlControls.HtmlGenericControl labels in this.Page.Form.Controls.OfType<System.Web.UI.HtmlControls.HtmlGenericControl>())
                       {
                           if (labels.ID.StartsWith("li_"))
                           {
                               if (menus.Contains("," + labels.ID.Replace("li_", "") + ","))
                               {
                                   labels.Visible = true;
                               }
                               else
                               {
                                   labels.Visible = false;
                               }
                           }
    
                           foreach (System.Web.UI.HtmlControls.HtmlAnchor anchor in labels.Page.Form.Controls.OfType<System.Web.UI.HtmlControls.HtmlAnchor>())
                           {
    
    
    
                               if (menus.Contains("," + anchor.ID + ","))
                               {
                                   anchor.Visible = true;
                               }
                               else
                               {
                                   anchor.Visible = false;
                               }
                           }


    }
    Posted
    Updated 28-Aug-16 20:09pm
    v2
    Comments
    Beginner Luck 29-Aug-16 2:17am    
    use title tag
    Member 10947681 29-Aug-16 3:22am    
    Hi thanks for your comment could u provide sample expmle how i use title tag in anchor tag

    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