arhame
asked on
Assigning a Nested Panel to not visible=false not working.
Good afternoon, I'm currently working in a control that looks like this:
Datalist1
Gridview
Datalist3
Panel
Gridview30
/Panel
Now my ultimate goal is that if some criteria is met, I want to set the Panel.Visible = False. I have the code working, that will find the Gridview and based on it's criteria set the Panel visible to false... however when the page is rendered it is still set to true. I know the code to set it to false is working because if I do:
Protected Sub DataList1_ItemDataBound(By Val sender As Object, ByVal e As System.Web.UI.WebControls. DataListIt emEventArg s) Handles DataList1.ItemDataBound
Dim Dl3 As DataList = CType(e.Item.FindControl(" Datalist3" ), DataList)
If Dl3.Items.Count <> 0 Then
Dim gv30 As GridView = CType(FindC("GridView30", DataList1.Controls), GridView)
Response.Write(gv30.Rows.C ount.ToStr ing() & ",")
If gv30.Rows.Count > 0 Then
Dim pnl1 As Panel = CType(FindC("pnlDStrut", DataList1.Controls), Panel)
pnl1.Visible = False
Response.Write(pnl1.Visibl e.ToString ()) <-------DISPLAYS "False" at the top of the page.----->
End If
End If
End Sub
However, the panel is still visible - I'm assuming since it's default property is true - that is somehow overriding what I set it to. Whatever the default mode is set to, that's how it's rendered on the page when it's done.
(FindC is a function that finds nested control, btw)
ANY ideas at all on how to fix this and have my code be the final say in it?
Datalist1
Gridview
Datalist3
Panel
Gridview30
/Panel
Now my ultimate goal is that if some criteria is met, I want to set the Panel.Visible = False. I have the code working, that will find the Gridview and based on it's criteria set the Panel visible to false... however when the page is rendered it is still set to true. I know the code to set it to false is working because if I do:
Protected Sub DataList1_ItemDataBound(By
Dim Dl3 As DataList = CType(e.Item.FindControl("
If Dl3.Items.Count <> 0 Then
Dim gv30 As GridView = CType(FindC("GridView30", DataList1.Controls), GridView)
Response.Write(gv30.Rows.C
If gv30.Rows.Count > 0 Then
Dim pnl1 As Panel = CType(FindC("pnlDStrut", DataList1.Controls), Panel)
pnl1.Visible = False
Response.Write(pnl1.Visibl
End If
End If
End Sub
However, the panel is still visible - I'm assuming since it's default property is true - that is somehow overriding what I set it to. Whatever the default mode is set to, that's how it's rendered on the page when it's done.
(FindC is a function that finds nested control, btw)
ANY ideas at all on how to fix this and have my code be the final say in it?
Have you tried changing from panel visble= false to just using bringtofront or senttoback?
ASKER
I believe those are for win forms - I'm doing this in a web application. Are those usable in a Web Application?
I have tried adding style instead of visible, like pnl1.style.add("display", "none") and that doesn't work either. I've noticed since that even if I try to set the Gridview's visibility to false, even that doesn't work. It accepts it and puts it in place according to code, but when the page gets rendered it's still there. There has to be a trick to doing this to nested controls.... it works on the first level of being nested, but not the 2nd....
I have tried adding style instead of visible, like pnl1.style.add("display", "none") and that doesn't work either. I've noticed since that even if I try to set the Gridview's visibility to false, even that doesn't work. It accepts it and puts it in place according to code, but when the page gets rendered it's still there. There has to be a trick to doing this to nested controls.... it works on the first level of being nested, but not the 2nd....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
vb jonas,
I had tried that before, under Datalist3 - it was giving me an object reference not found reference to the gridviews. However, I must have been doing something wrong. At your suggestion I tried it again, and I am actually able to get it working this way.
I tried that almost 2 full days ago, was the first way I tried it. I have no clue what I was doing wrong at the time, but since it's working now I won't complain. I think I was trying in my findc function to pass it Datalist3.Controls, isntead of Datalist1.Controls... maybe. Dunno. Either way, thanks for pushing me that direction again.
I had tried that before, under Datalist3 - it was giving me an object reference not found reference to the gridviews. However, I must have been doing something wrong. At your suggestion I tried it again, and I am actually able to get it working this way.
I tried that almost 2 full days ago, was the first way I tried it. I have no clue what I was doing wrong at the time, but since it's working now I won't complain. I think I was trying in my findc function to pass it Datalist3.Controls, isntead of Datalist1.Controls... maybe. Dunno. Either way, thanks for pushing me that direction again.
Protected Sub DataList3_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
Dim gv30 As GridView = CType(FindC("GridView30", DataList1.Controls), GridView)
If gv30.Rows.Count = 0 Then
Dim pnl1 As Panel = CType(FindC("pnlDStrut", DataList1.Controls), Panel)
pnl1.Visible = False
End If
Dim gv7 As GridView = CType(FindC("GridView7", DataList1.Controls), GridView)
If gv7.Rows.Count = 0 Then
Dim pnl1 As Panel = CType(FindC("pnlPStrut", DataList1.Controls), Panel)
pnl1.Visible = False
End If
Dim gv8 As GridView = CType(FindC("GridView8", DataList1.Controls), GridView)
If gv8.Rows.Count = 0 Then
Dim pnl1 As Panel = CType(FindC("pnlAStrut", DataList1.Controls), Panel)
pnl1.Visible = False
End If
End Sub
ASKER
Thanks, I'm going bald too quick as it! This was driving me crazy! It made no sense...