Display/Hide part of a list - asp.net

I have an (unordered)list (generated by a repeater) of items. However, I'd like to show the first three items, and have the rest hidden by the main content div. When a button is pressed, I would like the list's div to expand, pushing the main content div down and showing the rest of the list. I was thinking of using slideDown(), but that closes the entire div ( and I would like to show the first 3 items of the list). What would be the best way to achieve an effect like this? Is there a plugin that can easily show X items of a list and the display the rest upon request?
Thanks
edit: Adding current code:
<div id="name_links">
<asp:Repeater ID="rptName" runat="server">
<ItemTemplate>
<ul class="ul_links">
<li>
<a id="aName" runat="server" href=<%# Eval("Name")%> >
<%# Eval("Name")%>
</a>
</li>
</ul>
</ItemTemplate>
</asp:Repeater>
</div>
<div id="main_content" >
...
</div>
I've tried to add this JQuery, but it doesn't seem to pick up any of the links:
$("ul.ul_links").each(function() {
$(this).children("li:gt(3)").hide();
alert("Testing"); //This never gets called.
});

You item template looks wrong
It should be
<div id="name_links">
<ul class="ul_links">
<asp:Repeater ID="rptName" runat="server">
<ItemTemplate>
<li>
<a id="aName" runat="server" href=<%# Eval("Name")%> ><%# Eval("Name")%>
</a>
</li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
Then jquery will be able to show and hide as desired.
The other way you were creating sets of ul -> li tags .

This can be done with jQuery, but it would help to see example of your markup.
Here's a link showing how you could do it with ul/li tags. You should be able to adapt it to your own markup without too much trouble.
Typically you hide item 4 and out with:
$('div:gt(2)').hide(); //index starts at 0
You have to modify the jquery selector to fit your markup and you could put it in a $(document).ready() block in order to hide the items on page load.

Related

<a> tag not repeating correctly in asp:repeater

I have a repeater that shows a list of albums and each div is wrapped by a <a> tag. Ideally I would be able to click on the image and it would redirect me to the full album.
But what is actually happening that for some reason the <a> tag when spawned by the repeater does not wrap around the divs but instead just appears before the div it should be wrapping. See below...
and my code
<asp:Repeater runat="server" DataSourceID="Sqlds_Albums">
<ItemTemplate>
<div class="col-sm-4">
<a href="\">
<div class="image-card" style="background-image: url('<%# Eval("PhotoID","../Media/Gallery/{0}.jpg") %>')">
<div class="card-text-bottom">
<div class="album-link">
<asp:HyperLink ID="albumLink" Font-Bold="true" runat="server" Text='<%# Eval("Title") %>' NavigateUrl='<%# Eval("AlbumID","~/Album.aspx?AlbumID={0}") %>' />
</div>
<div class="album-nophotos">
<asp:Label ID="lbl_NofPhotos" runat="server" Text='<%# Eval("TotalPhotos","{0} Photos") %>'></asp:Label>
</div>
<div class="album-visits">
<asp:Label ID="lbl_NofVisits" ForeColor="#333333" Font-Size="11px" runat="server" Text='<%# Eval("NofVisit","(Visited {0} times)") %>'></asp:Label>
</div>
</div>
</div>
</a>
</div>
</ItemTemplate>
</asp:Repeater>
Rendered HTML
<div class="col-sm-4">
<a href="\">
</a>
<div class="image-card" style="background-image: url('../Media/Gallery/3568.jpg')"><a href="\">
</a>
<div class="card-text-bottom"><a href="\">
</a>
<div class="album-link"><a href="\">
</a><a id="Body_ctl00_albumLink_0" href="Album.aspx?AlbumID=99" style="font-weight:bold;">2017 Photos</a>
</div>
<div class="album-nophotos">
<span id="Body_ctl00_lbl_NofPhotos_0">24 Photos</span>
</div>
<div class="album-visits">
<span id="Body_ctl00_lbl_NofVisits_0" style="color:#333333;font-size:11px;">(Visited 683 times)</span>
</div>
</div>
</div>
What I tried
Used all the asp: hyperlinks, imagebutton, button etc but no luck.
as usual any guidance greatly appriciated.
EDIT
The problem was the hyperlink inside the .album-link div. Removing it fixed the issue but as recommended below will try to use a different approach to a link div.
In a nutshell, you're trying to do this:
<a><div></div></a>
Technically speaking, that's not valid HTML only valid for HTML5+, and not for HTML4. Under HTML4, <div> is a block-level element, <a> is an inline element, and in the strictest, most standards-compliant sense, inline elements are not allowed to contain block level elements. I know it's a pain; I used to do it all the time, too. But modern browsers now enforce this more strictly than they used to.
Since you're looking at album covers that are effectively images, one option is to use an actual img element, instead of setting the background on a div. This new element would fill the contents of the parent div. Then you can use css to overlay your labels on top of the image, and since img is an inline element you can nest that inside of your original <a> element.
If you have your heart set on keeping one div, the best solution I've seen is here:
Make a div into a link
If I had any clout with the W3C, I'd just add a new block-level link element already, or maybe just allow an href attribute on a few existing block-level elements.
Update:
Reading more on this, you might be able to fix this just by changing your DOCTYPE. The symptoms in the question are consistent with a browser treating this as HTML4, rather than HTML5. HTML4 still has the block/inline distinction, but HTML5 allows <a> to be either "flow-content" (block) or "phrasing-content" (inline).
With that in mind, this should be legal as long your browser knows to interpret this as an HTML5 document, rather than HTML4, which you can do by setting a doctype (which you should do anyway). Then the browser should stop needing to mangle your HTML to produce a compliant DOM.

script does not run on invisible asp:Panel after making it visible (ASP.Net)

I have an asp:Panel that I only make visible after a survey is completed. I have a script in the panel that displays a TripAdvisor widget. When the panel is made visible, the widget does not display. If I set the panel to visible when loading the survey, the widget does appear. How can I get the script to run after I make the panel visible? The asp:Panel code is below.
Thank you very much for any help.
<asp:Panel ID="PanelReviewSite" runat="server" CssClass="Panel" Visible="false">
<table>
<tr>
<td align="center">
<div id="TA_sswidecollectreview991" class="TA_sswidecollectreview">
<ul id="8XReiUtFMK2" class="TA_links R9Huu5J0oLD">
<li id="6lsEHIwyG34" class="RywVDRO81a">Write a review of <a target="_blank" href="http://www.tripadvisor.com/Hotel_Review-......">My Hotel</a></li>
</ul>
</div>
<script src="http://www.jscache.com/wejs?wtype=sswidecollectreview&uniq=991&locationId=81234&lang=en_US&border=true"></script>
</td>
</tr>
</table>
</asp:Panel>
Add to panel additional css class with display:none property in definition instead of using Visible property. And reset CssClass property back to Panel on survey completion.

How To: Manupilate SharePoint:AspMenu control (Style-wise)

What I want to do is to split-up the globalnavigation bar on the sharepoint 2010 so I can control what menu-items should be floated to the left or right of the bar.
Is there a way to do this without a complete customized version of it, so I only have to edit the current one. Or do I actually have to make a complete new one?
What I have tried so far is just copying all of the UL > LI's there's used to display the menu-items like this:
<div class="s4-tn">
<div class="menu horizontal menu-horizontal">
<ul class="static">
<li class="static dynamic-children">
<a href="#" CssClass="static dynamic-children menu-item">
<span class="additional-background">
<span class="menu-item-text">Custom Dropdown</span>
</span>
</a>
<ul class="dynamic">
<li class="dynamic">
<a href="#" class="dynamic menu-item">
<span class="additional-background">
<span class="menu-item-text">Test subsite</span>
</span>
</a>
</li>
</ul>
</li>
</ul>
</div>
</div>
But it doesn't seem to trigger the dropdown functionality. Might just be a naive attempt.
Any links to guides or tutorials about this subject would be a great help.
For future reference, here's the content from the linked blogpost.
This uses an asp:Repeater instead of a sharepoint:AspMenu as the former allows much cleaner html and better styling. Also I've created several datasources on the masterpage which return the correct items I need to display.
<asp:Repeater ID="TopMenu" runat="server" DataSourceID="selectedSiteMap">
<HeaderTemplate>
<ul id="main_menu_ul" class="">
</HeaderTemplate>
<ItemTemplate>
<li><a href="<%# Eval("Url")%>" class="link">
<%# Eval("Title")%></a></li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
<asp:SiteMapDataSource SiteMapProvider="CombinedNavSiteMapProvider" ShowStartingNode="false"
StartFromCurrentNode="false" StartingNodeOffset="0" StartingNodeUrl="sid:1002"
EnableViewState="true" ID="selectedSiteMap" runat="server" />
I found out which datasources to use with a little help of this post: http://ktskumar.wordpress.com/2008/04/14/sharepoint-navigation-providers-part-1/
They are listed for SharePoint 2007, but most work for 2010 also.
Using several repeaters and datasources on the page you can create a very clean menu. Along with some javascript and css styling you can create every menu you want.

Hide the html contorl from the server side without using attributes runat="Server"

I am using HTML control,and want to visible false from the server side with out using attributes runat="Server"
tell me any solution
Runat="Server" has got nothing to do with visibility.
If you want to hide the control (so that its not visible to any visitors to your site) you would simply set its CSS to visibility:hidden; or display: none;. I think this is what you wanted to know.
Wrap your html controls in an asp:placeholder control, and set the visibility on the placeholder.
Example
<asp:placeholder id="plc" runat="server" visible="false">
<h1>Some Content</h1>
<img src="/images/someimage.gif" alt="" />
</asp:placeholder>

Newline when using asp.net visible=false

when using asp.net´s visible=false e.g. for a htmlgenericcontrol asp.net renders a newline for a control that is set visible=false.
How to prevent this behavior?
I just have a
<ul> and then
<li runat="server" id="x"></li>
<li runat="server" id="x"></li>
<li runat="server" id="x"></li>
So one <li> per line. If I set one or all li´s to visible=false by code I get newlines instead of "Nothing"
Thanks.
Make sure there is no white space (spaces, tabs, new lines) around the control in the aspx page.
Try the following, all in one line:
<ul><li runat="server" id="x"></li><li runat="server" id="x"></li><li runat="server" id="x"></li></ul>

Resources