I have a treeview on my ASP.Net page and for some reason the text on some nodes gets cut off, I am programatically adding all the nodes and am aware of the existing issue listed here: http://support.microsoft.com/?scid=kb%3Ben-us%3B937215&x=8&y=13 however I am not changing the font and as you see in the code below this fix does not work for me.
Private Sub populateTreeView()
'Code that gets the data is here
Dim ParentIds As List(Of Integer) = New List(Of Integer)
For Each row As DataRow In ds.Rows
If ParentIds.Contains(row("ParentID")) Then
'' Do Nothing
Else
ParentIds.Add(row("ParentID"))
End If
Next
For Each Parent As Integer In ParentIds
Dim parentNode As New System.Web.UI.WebControls.TreeNode
For Each child In ds.Rows
If (child("ParentID") = Parent) Then
Dim childNode As New System.Web.UI.WebControls.TreeNode
parentNode.Text = child("ParentDescription")
parentNode.Value = child("ParentID")
parentNode.Expanded = False
childNode.Text = child("ChildDescription")
childNode.Value = child("ChildID")
parentNode.SelectAction = TreeNodeSelectAction.None
parentNode.ChildNodes.Add(childNode)
End If
Next
trvItem.Nodes.Add(parentNode)
Next
'This is just added to test the MS fix
trvItem.Nodes(0).Text += String.Empty
End Sub
The strange thing is that this issue only appears in IE, I have tested it in chrome and Firefox and both browsers display the text perfectly.
When I select a node this fixes the problem and all text displays as normal.
Any ideas as to what is going wrong here would be great as I'm clueless right now.
Thanks
tv1.LabelEdit = True
tv1.Nodes(0).Nodes(0).BeginEdit()
tv1.Nodes(0).Nodes(0).NodeFont = oNewFont
tv1.Nodes(0).Nodes(0).EndEdit(False)
tv1.LabelEdit = False
Marking this as closed since I never received an answer which solved the problem.
I managed to work around it by using the javascript postback to select one of the items on load, thus forcing the text to display correctly. I think this is an extension of the bug I linked in my original question.
Related
I am trying to access 3 checkboxes on a page that were created dynamically from database info on PageLoad.
I can see these checkboxes in the web Page Source with ID's equal to T1, T2 and T3. On viewing the page the boxes are checked or unchecked appropriately according to database table values.
I am trying to determine the checked or unchecked states of these checkboxes and then writing it to the database on a button click. All of that is fine.
My problem is the actual "accessing" of those checkboxes/their associated ID's. I have extensively researched and tried everything yet nothing seems to work. I'm sure I'm missing some little nuance.
Here's my code (sorry the indenting is screwed up):
Dim RecCountT As Integer = TNotify.Rows.Count
For i = 0 to RecCountT - 1
Dim strSQLNotifyT as String = "UPDATE dbo._PinCodes SET TextOnOff = #TextOnOff WHERE EmployeeID = #EmployeeID"
Dim myCommand as New SqlCommand(strSQLNotifyT, Conn)
Dim CheckBoxID
CheckBoxID = "T" & i
If CheckBoxID.Checked = True Then
myCommand.Parameters.AddWithValue("#TextOnOff", "on")
ElseIf CheckBoxID.Checked = False Then
myCommand.Parameters.AddWithValue("#TextOnOff", "off")
End If
myCommand.Parameters.AddWithValue("#EmployeeID", TNotify.Rows(i)("EmployeeID").ToString())
Conn.Open()
myCommand.ExecuteNonQuery()
Conn.Close()
Next
Since I do not see the checkbox creation code and assuming the checkBox is created successully and added to the Controls collection, when you create the CheckBox, add:
yourCheckBox.ClientIDMode = ClientIDMode.Static
If this does not work, edit your post with more relevant code to replicate the issue.
I am trying to integrate an adapter to get support for the OptGroup tag in .net. i took the same adapter as i usually did (been a while, but no build errors or warnings). I set attributes when i add items into the DropDownList, and attempt to read them in the adapter and they seem to be set to Nothing. I entered breakpoints at points of interest and after being set, i can see the Attributes having a value. And in the adapter, the item remains but without said attribute.
To get every possible glitch out of the way i went into full hardcode for adding items, and here we have the result. The display does not group up, as the !=nothing never is met on the adapter.
declaration of list:
Dim item1 As New ListItem("potatoes", "1")
item1.Attributes("OptionGroup") = "optionGroup1"
Dim item2 As New ListItem("Onions", "2")
item2.Attributes("OptionGroup") = "optionGroup2" 'here the optiongroup is set, and debugger sees value to it.
Me.cboMaterial.Items.Add(item1)
Me.cboMaterial.Items.Add(item2)
where it fails in the adapter:
Dim list As DropDownList = Me.Control
Dim currentOptionGroup As String = ""
Dim renderedOptionGroups As New Collection
For Each item As ListItem In list.Items
If item.Attributes("OptionGroup") = "" Then 'here, the item is worth something (potatoes) but the OptionGroup is nothing.
RenderListItem(item, writer)
Else
If currentOptionGroup <> item.Attributes("OptionGroup") Then
If currentOptionGroup <> "" Then
RenderOptionGroupEndTag(writer)
End If
currentOptionGroup = item.Attributes("OptionGroup")
RenderOptionGroupBeginTag(currentOptionGroup, writer)
End If
RenderListItem(item, writer)
End If
Next
i must be missing something, perhaps trivial, but I've been looking at the same thing for too long. any help would be welcome.
edit: i have tried adding the attribute with secondary syntax... by desperation i guess.
item2.Attributes.Add("OptionGroup","optionGroup2")
it changes nothing :P
I have a menu as a treeview and what I'm trying to do is make whatever treenode the user selects not selectable again unless he goes to a different page. How would I do this in asp.net and vb?
update:
ok so far this is what I have going on in the treenode selection changed sub
ViewState(10) = TreeView1.SelectedNode
TreeView1.SelectedNode.SelectAction = TreeNodeSelectAction.None
If ViewState(10).valuepath <> TreeView1.SelectedNode.ValuePath Then
TreeView1.SelectedNode.SelectAction = TreeNodeSelectAction.Select
End If
im sure the experts out there know exactly why this wouldn't work though I was surprised it complied. Anyways This gives me an error though I can't think of another way to keep that selected node in
UPDATE:
ViewState(10) = TreeView1.SelectedNode.DataItem
If ViewState(10) <> TreeView1.SelectedNode.DataItem Then
TreeView1.SelectedNode.Selected = ViewState(10)
TreeView1.SelectedNode.SelectAction = TreeNodeSelectAction.Select
Else
TreeView1.SelectedNode.SelectAction = TreeNodeSelectAction.None
End If
This works for the selectaction.none which is exactly what I wanted but I'm having troubles enabling it again when the user selects another treenode.
This is the answer for anyone who needs this in the future
For Each n As TreeNode In TreeView1.Nodes
For Each a As TreeNode In n.ChildNodes
If a.Selected = True Then
a.SelectAction = TreeNodeSelectAction.None
Else
a.SelectAction = TreeNodeSelectAction.Select
End If
Next
Next
I have a User Control which returns a table of data, which in some cases needs to be looped, displaying one on top of another.
I am able to dynamically add a single instance of this by placing a fixed placeholder in the page.
I am now trying to work out how to add more than one, given that I don't know how many might be needed I don't want to hard code the Placeholders.
I've tried the following, but I am just getting one instance, presumably the first is being overwritten by the second
My HTML
<div id="showHere" runt="server"/>
VB
Dim thisPh As New PlaceHolder
thisPh.Controls.Add(showTable)
showHere.Controls.Add(thisPh)
Dim anotherPh As New PlaceHolder
anotherPh .Controls.Add(showTable)
showHere.Controls.Add(anotherPh)
How do I make it add repeated tables within the showHere div?
I would advise generating a different ID for each of your table. For example,
Dim i As Integer
i = 0
For each tbl in ShowTables
tbl.ID = "MyTab" + i.ToString()
i = i + 1
showHere.Controls.Add(tbl)
showHere.Controls.Add(New LiteralControl("<br />"))
Next
On other hand, it would make more sense to have a your user/custom control generate html for a single table and then nest your user/custom control within a repeater (or similar control such as ListView etc).
Did you tried simply, this:
For each tbl in ShowTables
showHere.Controls.Add(tbl)
showHere.Controls.Add(New LiteralControl("<br />"))
Next
After fussing with this issue myself, I stumbled across below solution.
On button click()
LocationDiv.Visible = True
Dim existingItems As New List(Of Object)
If Not Session("existingItems") Is Nothing Then
existingItems = CType(Session("existingItems"), List(Of Object))
For Each item As Object In existingItems
LocationDiv.Controls.Add(item)
Next
existingItems.Clear()
End If
LocationDiv.Controls.Add(New LiteralControl("<b>" & Text & "</b>"))
For Each item As Object In LocationDiv.Controls
existingItems.Add(item)
Next
Session.Add("existingItems", existingItems)
I have created an VB.NET page to record views for ads and will call page from img src.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Dim insert_number As Integer = 0
Dim ad_id As Integer = 0
If Request.QueryString("adid") Is Nothing Then
ad_id = 0
Else
If Not Integer.TryParse(Request.QueryString("adid"), ad_id) Then
ad_id = 0
End If
End If
Dim connectStr As String = System.Configuration.ConfigurationManager.AppSettings("connectStr").ToString()
Dim myconnection As SqlConnection = New SqlConnection(connectStr)
Dim mySqlCommand As SqlCommand
myconnection.Open()
Try
mySqlCommand = New SqlCommand("sp_record", myconnection)
mySqlCommand.CommandType = CommandType.StoredProcedure
mySqlCommand.Parameters.AddWithValue("#record_id", ad_id)
insert_number = mySqlCommand.ExecuteNonQuery()
Catch ex As Exception
End Try
myconnection.Close()
Dim oBitmap As Bitmap = New Bitmap(1, 1)
Dim oGraphic As Graphics = Graphics.FromImage(oBitmap)
oGraphic.DrawLine(New Pen(Color.Red), 0, 0, 1, 1)
'Response.Clear()
Response.ContentType = "image/gif"
oBitmap.Save(Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif)
'oBitmap.Dispose()
'oGraphic.Dispose()
End Sub
Unless I comment oBitmap.Save line, the code runs twice and it makes two inserts (store prcoedure runs twice) to Database.
I have tried AutoEventWireup = "true" and "false" at #PAGE. "true" runs code twice, "false" did not do anything (no error) and did not give any output as well.
I have also tried following version of creating 1pixel image output but it did run twice as well (it requires aspcompat=true in #PAGE part):
'Response.ContentType = "image/gif"
'Dim objStream As Object
'objStream = Server.CreateObject("ADODB.Stream")
'objStream.open()
'objStream.type = 1
'objStream.loadfromfile("c:\1pixel.gif")
'Response.BinaryWrite(objStream.read)
Any ideas are welcome.
You may want to do an onload function for the image to see why it's being called a second time. I'm guessing that it's getting loaded somewhere in the preload and then being called (.Save) during the page load as well and that's why you're seeing the double entry.
If you are trying to get unique page loads, you may want to try putting the oBitmap.Save line within a check for postback like this within the page load:
If Page.IsPostback = False Then
'Bitmap Code Here
End If
And see if that fixes it for you.
If you're loading data from a database, you'll want to make sure that it also is within that PostBack check (because a. you're loading the data twice and b. it can cause these double postbacks in some circumstances).
Edit: Wanted to edit code section to include all bitmap code, not just the save.
Not sure about the specifics, but that is a lot of code within in Page_Load function.
Generally, the way I would solve this type of problem is to have some sort of page arguments that you can check for in order to do the correct things. Either add some get/post parameters to the call that you can check for or check things like the Page.IsPostBack.
I realize this is an old post but I had an similar issue where the page was firing twice on the postback. I found several posts sugesting what is being dicusses here. However, what corrected my issue was setting the page directive property AutoEventWireup=false at the page level.
Here is a good article How to use the AutoEventWireup attribute in an ASP.NET Web Form by using Visual C# .NET that helped me solve this.
Hope this helps!
Risho