VisuallyImpared
01-18-2007, 05:58 AM
Hey folks,
I am creating my own tree nodes with some special properties. One of which is a node image(icon) that has some javascript elements added to the htmlattributes.
This works fine on the initial load but the node images dissapear after a post back.
Here is how the nodes are being generated (the application is loading a bill of materials)
1) The user selects a component
2) The application goes to the database and retrieves all the sub-components and returns them in a dataset.
3) Each row of the dataset is stepped through and a node is added to the tree. The icon for each node is dependant on the part type data for that part (a mechanical part gets a screw icon, an electrical part gets a PCB icon, etc.)
4) The javascript added to the icon htmlattributes adds an 'onmouseover' routine to the icon. so when the user hvers over the part icon the part# BOM quantity, Description, etc appear in a floating window over teh mouse.
5) If the user clicks on a subassembly with sub assemblies of its own the application does the same thing as it did before (gets a dataset and adds nodes) this time the nodes are added to the selected node.
This goes on and on down the assemblies untill there are no more sub assemblies. As I said it work perfectly BUT there is one problem:
Only the newest level of the BOM contains the Icons with the JavaScript Tags. As soon as there is a postback the nodes lose their icons and the attached htmlattributes.
Anyone have any idea how to make these custom nodes survive a postback?
Here is my overloaded treenode:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Public Class ExtendedTreeview
Inherits TreeNode
Private M_Lib As ListDictionary
Private _Ico As Image
Public Property Part_Ico() As Image
Get
Return _Ico
End Get
Set(ByVal value As Image)
_Ico = value
End Set
End Property
Public Property Status_Icon() As ListDictionary
Get
Return M_Lib
End Get
Set(ByVal value As ListDictionary)
M_Lib = value
End Set
End Property
Protected Overrides Sub RenderPretext(ByVal writer As HtmlTextWriter)
Dim DE As DictionaryEntry
Dim PN As String
Dim Desc As String
If Not M_Lib Is Nothing Then
PN = M_Lib("PartNo")
Desc = M_Lib("Desc")
End If
With _Ico
writer.AddAttribute("src", _Ico.ImageUrl.ToString.Substring(2))
writer.AddAttribute("onmouseover", "return overlib('<b>Part Number:</b> " & _
PN & "<br><b>Description:</b> " & Desc & "', CSSCLASS)")
writer.AddAttribute("onmouseout", "return nd()")
writer.RenderBeginTag(HtmlTextWriterTag.Img)
writer.RenderEndTag()
End With
End Sub
End Class
And here is how I create the node:
Protected Sub treeBOM_SelectedNodeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles treeBOM.SelectedNodeChanged
Dim ObjParts As New VisualPartsService 'my webservice that gets parts info for me
Dim ReturnedValues As New DataSet
Dim PN As String = treeBOM.SelectedNode.Value.Split("|")(0)
Dim REV As String = treeBOM.SelectedNode.Value.Split("|")(1)
ReturnedValues = ObjParts.GetAssemblyParts(PN, REV)
If ReturnedValues.Tables.Count > 0 Then
If ReturnedValues.Tables(0).Rows.Count > 0 Then
Dim DR As DataRow
For Each DR In ReturnedValues.Tables(0).Rows
Dim objPart As New VisualPartsService
Dim MyPart As New PartDetails
MyPart = objPart.GetPartDetails(DR("PartNumber"))
Dim NewNode As New ExtendedTreeView
NewNode.Text = "PN: " & DR("PartNumber") & " Rev: " & DR("Revision")
NewNode.Value = DR("PartNumber") & "|" & DR("Revision")
Dim im As New Image
im.ImageUrl = GetNodeImage(DR("B2PARTTYPE"))
Dim SI As New ListDictionary
SI.Add("PartNo", MyPart.PartNumber)
SI.Add("Desc", MyPart.Description)
NewNode.Status_Icon = SI
NewNode.Part_Ico = im
treeBOM.SelectedNode.ChildNodes.Add(NewNode)
Next
End If
End If
treeBOM.SelectedNode.Expand()
End Sub
I am creating my own tree nodes with some special properties. One of which is a node image(icon) that has some javascript elements added to the htmlattributes.
This works fine on the initial load but the node images dissapear after a post back.
Here is how the nodes are being generated (the application is loading a bill of materials)
1) The user selects a component
2) The application goes to the database and retrieves all the sub-components and returns them in a dataset.
3) Each row of the dataset is stepped through and a node is added to the tree. The icon for each node is dependant on the part type data for that part (a mechanical part gets a screw icon, an electrical part gets a PCB icon, etc.)
4) The javascript added to the icon htmlattributes adds an 'onmouseover' routine to the icon. so when the user hvers over the part icon the part# BOM quantity, Description, etc appear in a floating window over teh mouse.
5) If the user clicks on a subassembly with sub assemblies of its own the application does the same thing as it did before (gets a dataset and adds nodes) this time the nodes are added to the selected node.
This goes on and on down the assemblies untill there are no more sub assemblies. As I said it work perfectly BUT there is one problem:
Only the newest level of the BOM contains the Icons with the JavaScript Tags. As soon as there is a postback the nodes lose their icons and the attached htmlattributes.
Anyone have any idea how to make these custom nodes survive a postback?
Here is my overloaded treenode:
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Public Class ExtendedTreeview
Inherits TreeNode
Private M_Lib As ListDictionary
Private _Ico As Image
Public Property Part_Ico() As Image
Get
Return _Ico
End Get
Set(ByVal value As Image)
_Ico = value
End Set
End Property
Public Property Status_Icon() As ListDictionary
Get
Return M_Lib
End Get
Set(ByVal value As ListDictionary)
M_Lib = value
End Set
End Property
Protected Overrides Sub RenderPretext(ByVal writer As HtmlTextWriter)
Dim DE As DictionaryEntry
Dim PN As String
Dim Desc As String
If Not M_Lib Is Nothing Then
PN = M_Lib("PartNo")
Desc = M_Lib("Desc")
End If
With _Ico
writer.AddAttribute("src", _Ico.ImageUrl.ToString.Substring(2))
writer.AddAttribute("onmouseover", "return overlib('<b>Part Number:</b> " & _
PN & "<br><b>Description:</b> " & Desc & "', CSSCLASS)")
writer.AddAttribute("onmouseout", "return nd()")
writer.RenderBeginTag(HtmlTextWriterTag.Img)
writer.RenderEndTag()
End With
End Sub
End Class
And here is how I create the node:
Protected Sub treeBOM_SelectedNodeChanged(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles treeBOM.SelectedNodeChanged
Dim ObjParts As New VisualPartsService 'my webservice that gets parts info for me
Dim ReturnedValues As New DataSet
Dim PN As String = treeBOM.SelectedNode.Value.Split("|")(0)
Dim REV As String = treeBOM.SelectedNode.Value.Split("|")(1)
ReturnedValues = ObjParts.GetAssemblyParts(PN, REV)
If ReturnedValues.Tables.Count > 0 Then
If ReturnedValues.Tables(0).Rows.Count > 0 Then
Dim DR As DataRow
For Each DR In ReturnedValues.Tables(0).Rows
Dim objPart As New VisualPartsService
Dim MyPart As New PartDetails
MyPart = objPart.GetPartDetails(DR("PartNumber"))
Dim NewNode As New ExtendedTreeView
NewNode.Text = "PN: " & DR("PartNumber") & " Rev: " & DR("Revision")
NewNode.Value = DR("PartNumber") & "|" & DR("Revision")
Dim im As New Image
im.ImageUrl = GetNodeImage(DR("B2PARTTYPE"))
Dim SI As New ListDictionary
SI.Add("PartNo", MyPart.PartNumber)
SI.Add("Desc", MyPart.Description)
NewNode.Status_Icon = SI
NewNode.Part_Ico = im
treeBOM.SelectedNode.ChildNodes.Add(NewNode)
Next
End If
End If
treeBOM.SelectedNode.Expand()
End Sub