I wrote this control that make tablecells and assigns the ID of lets say hmcI0. Control works fine on a regular page, because I wrote and tested it on a regular page.
When you place the control on a masterpage, the ID of the tablecell changes to ct100_hmcI0, because it's on a masterpage. I sort of understand why, content place holder value
The tablecell also has some javascript mouseover(ShowChildPanel('hmcI0') which now needs to be mouseover(ShowChildPanel('ct100_hmcI0')) if in a master page
I'm not sure how to go about handling the whole situation
If my control is on a regular page, all is good.
I create my parent container called hmcI0
Dim table As Table
table = New Table
table.CellPadding = 0
table.CellSpacing = 0
table.Height = [Height]
table.Width = [Width]
table.Style.Add(HtmlTextWriterStyle.TextAlign, [MenuAlignment].ToString)
table.BorderWidth = [BorderWidth]
table.BorderColor = [BorderColor]
table.BorderStyle = [BorderStyle]
table.CssClass = [CssClass]
table.ToolTip = [ToolTip]
panel.Controls.Add(table)
Dim trMenu As TableRow
trMenu = New TableRow
table.Controls.Add(trMenu)
Dim tdMenu As TableCell
tdMenu = New TableCell
tdMenu.ID = "hmcI" & idx.ToString
Dim DDP_TR As TableRow DDP_TR = New TableRow DDP_Table.Controls.Add(DDP_TR)
Dim DDP_TD1 As TableCell DDP_TD1 = New TableCell DDP_TD1.Attributes.Add("id", "hmcG1T" & idx.ToString) DDP_TD1.Text = c_Value DDP_TD1.CssClass = c_Css DDP_TD1.Height = c_Height DDP_TD1.Width = c_Width DDP_TD1.Style.Add("nowrap", "nowrap") DDP_TD1.VerticalAlign = VerticalAlign.Top DDP_TR.Controls.Add(DDP_TD1)
I call this javascript to turn on the child panel, and move it to the right and down some
function ShowChildPanel(parentId, id) { var browserType; var parentPosition; parentPostion = findParentPosition(parentId); var childX = parentPostion[0]; var childY = parentPostion[1] + 26;
If you are generating the table cells in the code-behind, you can use the ClientID property, which gives you the ID as it will be when the HTML is rendered...
I started thinking that maybe when you use the control property ID, the ID changes name on a masterpage. What would happen if I just manually added an attribute called ID.
Works!, but I'm not sure how stable it is. Well keep an eye on it, then mark it resolved later.
Dim tdMenu As TableCell
tdMenu = New TableCell
tdMenu.ID = "hmcI" & idx.ToString 'Changed from this
tdMenu.Attributes.Add("id", "hmcI" & idx.ToString) ' To This
tdMenu.Attributes.Add("onmousseover", "ShowChildPanel('" & tdMenu.ClientID & "', 'hmcG" & idx.ToString & "')")
tdMenu.Attributes.Add("onmouseout", "HideChildPanel('" & tdMenu.ClientID & "', 'hmcG" & idx.ToString & "')")
trMenu.Controls.Add(tdMenu)
Marked as answer by jkirkerx on Mar 30, 2008 11:19 PM
jkirkerx
Contributor
3750 Points
873 Posts
ct100, masterpages and embedded javascript - Id names
Mar 27, 2008 06:02 PM|LINK
I wrote this control that make tablecells and assigns the ID of lets say hmcI0. Control works fine on a regular page, because I wrote and tested it on a regular page.
When you place the control on a masterpage, the ID of the tablecell changes to ct100_hmcI0, because it's on a masterpage. I sort of understand why, content place holder value
The tablecell also has some javascript mouseover(ShowChildPanel('hmcI0') which now needs to be mouseover(ShowChildPanel('ct100_hmcI0')) if in a master page
I'm not sure how to go about handling the whole situation
If my control is on a regular page, all is good.
I create my parent container called hmcI0
I call this javascript to turn on the child panel, and move it to the right and down some
doyleits
Contributor
3580 Points
549 Posts
Re: ct100, masterpages and embedded javascript - Id names
Mar 27, 2008 08:35 PM|LINK
If you are generating the table cells in the code-behind, you can use the ClientID property, which gives you the ID as it will be when the HTML is rendered...
myTableCell.Attributes("onmouseover") = "findParentPosition('" & myTableCell.ClientID & "');"Collabroscape LLC [www.collabroscape.com]
jkirkerx
Contributor
3750 Points
873 Posts
Re: ct100, masterpages and embedded javascript - Id names
Mar 27, 2008 10:46 PM|LINK
I started thinking that maybe when you use the control property ID, the ID changes name on a masterpage. What would happen if I just manually added an attribute called ID.
Works!, but I'm not sure how stable it is. Well keep an eye on it, then mark it resolved later.
Dim tdMenu As TableCell tdMenu = New TableCell tdMenu.ID = "hmcI" & idx.ToString 'Changed from this tdMenu.Attributes.Add("id", "hmcI" & idx.ToString) ' To This tdMenu.Attributes.Add("onmousseover", "ShowChildPanel('" & tdMenu.ClientID & "', 'hmcG" & idx.ToString & "')") tdMenu.Attributes.Add("onmouseout", "HideChildPanel('" & tdMenu.ClientID & "', 'hmcG" & idx.ToString & "')") trMenu.Controls.Add(tdMenu)