vbnetcoder
asked on
div tags - asp.net 3.5 app
I have div tags in my html code (see the code example bellow)
Now, I am trying to make them visible and invisible (based on criteria) in my asp.net code by doing this:
div1.Style("Display") = True
div2.Style("Display") = "none"
But it tells me that Div1 "is not declared."
<asp:Repeater ID="Repeater1" runat="server">
<%-- <headertemplate>
</headertemplate>--%>
<ItemTemplate>
<font size="2" <b><label style="padding-right:93px; ">Category ID</label><%#Eval("Categor y_ID")%></ font>
<br />
<font size="2" ><label style="padding-right:82px; ">Category Path</label><%#Eval("Categ ory_ID")%> </font>
<br />
<font size="2"><label style="padding-right:126px ;">Name</l abel><%#Ev al("Catego ry_Name")% ></font>
<br />
<font size="2"><label style="padding-right:93px; ">Descript ion</label ><%#Eval(" Category_D escription ")%></font >
<br />
<font size="2"><label style="padding-right:67px; ">Parent Category</label><%#Eval("P arent_Cate gory_ID")% ></font>
<br />
<div id="div1" runat="server">
<asp:Label ID="lblNoMainImage" runat="server" Text="No Image"></asp:Label>
</div>
<div id="div2" runat="server">
<asp:HyperLink ID="hlMainImageView2" NavigateUrl="javascript:Op enChild('m ain');"
runat="server">View</asp:H yperLink>
</div>
<br />
</ItemTemplate>
</asp:Repeater>
Now, I am trying to make them visible and invisible (based on criteria) in my asp.net code by doing this:
div1.Style("Display") = True
div2.Style("Display") = "none"
But it tells me that Div1 "is not declared."
<asp:Repeater ID="Repeater1" runat="server">
<%-- <headertemplate>
</headertemplate>--%>
<ItemTemplate>
<font size="2" <b><label style="padding-right:93px;
<br />
<font size="2" ><label style="padding-right:82px;
<br />
<font size="2"><label style="padding-right:126px
<br />
<font size="2"><label style="padding-right:93px;
<br />
<font size="2"><label style="padding-right:67px;
<br />
<div id="div1" runat="server">
<asp:Label ID="lblNoMainImage" runat="server" Text="No Image"></asp:Label>
</div>
<div id="div2" runat="server">
<asp:HyperLink ID="hlMainImageView2" NavigateUrl="javascript:Op
runat="server">View</asp:H
</div>
<br />
</ItemTemplate>
</asp:Repeater>
Since the Divs are in a repeater control, they aren't listed in the Page.Controls collection. Insteadm they are in the Repeater.Controls collections. I suggest something like Repeater1.Controls.FindCon trol("div1 "). I haven't tried this, but I'm sure its very close.
as an aside the opposite of
div1.Style("Display") = "none"
is
div1.Style("Display") = ""
div1.Style("Display") = "none"
is
div1.Style("Display") = ""
ASKER
Webmonkey:
How what would be the code then to make the divs visible or invisible?
How what would be the code then to make the divs visible or invisible?
to make invisible :
div.Style("display") = "none"
to make visible :
div.Style("display") = ""
div.Style("display") = "none"
to make visible :
div.Style("display") = ""
Hi, first you have to use the css for creating the div design then after you have to set the visible property of div into your coding part.
ASKER
How would i do that in conjunction with the find method...
simply doing this will not work:
Repeater1.FindControl("div 1")
Repeater1.FindControl("div 2")
div1.Style("Display") = True
div2.Style("Display") = "none"
simply doing this will not work:
Repeater1.FindControl("div
Repeater1.FindControl("div
div1.Style("Display") = True
div2.Style("Display") = "none"
try this :
Repeater1.FindControl("div 1").Style( "display") = "none"
However you may be better doing it in javascript.
A good artile for what you are trying to achieve :
http://www.4guysfromrolla. com/articl es/091504- 1.aspx#pos tadlink
Repeater1.FindControl("div
However you may be better doing it in javascript.
A good artile for what you are trying to achieve :
http://www.4guysfromrolla.
If you want to use CSS to hide the control, then you could use:
If you don't want the server to send the control at all, then you would address the visible property in .Net, like so:
Repeater1.FindControl("div1").Style("display") = "none";
If you don't want the server to send the control at all, then you would address the visible property in .Net, like so:
Repeater1.FindControl("div1").Visible = False;
ASKER
When I do that it tells me that style is not a member of system.web.ui.control
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I still get style is not a member of system.web.ui.control
What version of the .Net Framework are you using?
ASKER
ty