Monday, March 26, 2012

Web Controls-Treeview: Problem of Single quotes in TreeNode value

Hi,

I am trying to generate a .NET page ("Page 2") which holds the Treeview and its nodes dynamically generated through another .NET page("Page 1").

When"Page 1" loads, it calls the database and fetches the table values and creates"Page 2" on the server by writing the information from the database in the treeview format and finally redirects to"Page 2". Thus it displays the treeview structure.

I am having a problem here. One of the fieldsRegionName has valueO'Neals. When I try to add the region, It does create "Page 2" withO'Neals as one of the Nodes... But gives error when the page is redirected.. This is happening because it thinks that theRegionName ends atO.

I have included some part of my code here for a better understanding of my problem.

---------------
PAGE 1

RegionName = DS.Tables("Region").Rows(I).Item("RegionName").ToString()

objStreamWriter.WriteLine("<ie:TreeNode Text='<font face=Arial, Verdana>"+RegionName+"</font>' DefaultStyle='background:none;color:blue;font-size:8pt' HoverStyle='background:none;color:blue;font-name:Arial, Verdana' SelectedStyle='background:none;color:blue;font-name:Arial, Verdana' NavigateUrl='CustomizeByCategory.asp?LogonName="+LogonName+"&RegionName="+RegionName+"' Target='_top'>")

---------------

PAGE 2

<ie:TreeView runat='server'>
<ie:TreeNode Text='<font face=Arial, Verdana>O'Neals</font>' DefaultStyle='background:none;color:blue;font-size:8pt' HoverStyle='background:none;color:blue;font-name:Arial, Verdana' SelectedStyle='background:none;color:blue;font-name:Arial, Verdana' NavigateUrl='CustomizeByCategory.asp?LogonName=demotest&RegionName=O'Neals' target='_top' EXPANDED='true'>
</ie:TreeNode>
</ie:TreeView
----------------
ERROR

Parser Error Message: Type 'Microsoft.Web.UI.WebControls.TreeNode' does not have a property named 'face'.

I tried replacing the RegionName value where its' ; with\', but still it doesnt work. Any thoughts and suggestions are welcome. Please respond as soon as possible.

Thanks!Try encoding it with something like
´ ;
without the space.

Joe
Hi Joe,

Thanks for your quick reply. That did help me to get rid of the error in the treeview. Thats was a very good trick!!!!!!.

It didnt help me much by replacing' with´ because its breaking the navigate url when navigated... It thinks the value is justO coz it breaks at&. But it did help me when I replace it directly with`.

and shows the node as O`Neals. and its fine.. My code works great. I did something like this.

---------------
PAGE 1 With Changes

RegionName = DS.Tables("Region").Rows(I).Item("RegionName").ToString()
RegionName = Replace(RegionName, "'", "`")
objStreamWriter.WriteLine("<ie:TreeNode Text='<font face=Arial, Verdana>"+RegionName+"</font>' DefaultStyle='background:none;color:blue;font-size:8pt' HoverStyle='background:none;color:blue;font-name:Arial, Verdana' SelectedStyle='background:none;color:blue;font-name:Arial, Verdana' NavigateUrl='CustomizeByCategory.asp?LogonName="+LogonName+"&RegionName="+RegionName+"' Target='_top'>")

---------------

Thanks a bunch!

0 comments:

Post a Comment