ClientID's ????
-
Hello! I'm quite new to the ASP.NET world and I'm trying to build a menu with sub menu items, I know that their is a pre-build Menu control but I still want to create my own. I'm only facing the last problem. The clientID's? I've this recursive function:
private Panel GetMenu(int ParentID) { stefw.Database.Page objPage = new stefw.Database.Page(); Panel pnlBox = new Panel(); DataTable dtItems = objPage.GetChildPages(ParentID); foreach (DataRow drItem in dtItems.Rows) { string url = "Default.aspx?Page=" + drItem["PageID"].ToString(); string name = drItem["Name"].ToString(); string link = "[" + name + "](\"")"; Panel pnlItem = new Panel(); pnlItem.ID = "Item" + drItem["PageID"].ToString(); pnlItem.Controls.Add(new LiteralControl(link)); pnlItem.CssClass = "Item"; if (drItem["HasChildren"].ToString() == "1") { Panel child = GetMenu(int.Parse(drItem["PageID"].ToString())); pnlBox.Attributes.Add("onMouseOver", "document.getElementByID('" + child.ClientID + "').style.overflow='visible'"); pnlItem.Controls.Add(child); } pnlBox.Controls.Add(pnlItem); } if (ParentID == -1) pnlBox.CssClass = "MainItem"; else pnlBox.CssClass = "Box"; pnlBox.ID = "Box" + ParentID.ToString(); return pnlBox; }
and it gives this output:[Home](Default.aspx?Page=1) [Informatie](Default.aspx?Page=3) [Beheer](Default.aspx?Page=2)
You can see that it goes wrong at this line: [document.getElementByID('Box1').style.overflow='visible'"] and here [pnlBox.Attributes.Add("onMouseOver", "document.getElemen -
Hello! I'm quite new to the ASP.NET world and I'm trying to build a menu with sub menu items, I know that their is a pre-build Menu control but I still want to create my own. I'm only facing the last problem. The clientID's? I've this recursive function:
private Panel GetMenu(int ParentID) { stefw.Database.Page objPage = new stefw.Database.Page(); Panel pnlBox = new Panel(); DataTable dtItems = objPage.GetChildPages(ParentID); foreach (DataRow drItem in dtItems.Rows) { string url = "Default.aspx?Page=" + drItem["PageID"].ToString(); string name = drItem["Name"].ToString(); string link = "[" + name + "](\"")"; Panel pnlItem = new Panel(); pnlItem.ID = "Item" + drItem["PageID"].ToString(); pnlItem.Controls.Add(new LiteralControl(link)); pnlItem.CssClass = "Item"; if (drItem["HasChildren"].ToString() == "1") { Panel child = GetMenu(int.Parse(drItem["PageID"].ToString())); pnlBox.Attributes.Add("onMouseOver", "document.getElementByID('" + child.ClientID + "').style.overflow='visible'"); pnlItem.Controls.Add(child); } pnlBox.Controls.Add(pnlItem); } if (ParentID == -1) pnlBox.CssClass = "MainItem"; else pnlBox.CssClass = "Box"; pnlBox.ID = "Box" + ParentID.ToString(); return pnlBox; }
and it gives this output:[Home](Default.aspx?Page=1) [Informatie](Default.aspx?Page=3) [Beheer](Default.aspx?Page=2)
You can see that it goes wrong at this line: [document.getElementByID('Box1').style.overflow='visible'"] and here [pnlBox.Attributes.Add("onMouseOver", "document.getElemenClientID is the id that the client sees. If you look at the source of your page from the browser (after it has been processed) your id's get changed to things like ctl00_YourID. There is a property for the controls called ClientID that you can assign the id so that you can access it with javascript on the client (this only matters for controls with runat="server").