Newline when using asp.net visible=false - asp.net

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>

Related

Put an asp label under another without space between them

In a column I have a div container which contains two asp labels, one under the other.
<td>
<div>
<h2><asp:Label runat="server" ID="lblEmployeeFullname" Text="Claudie"></asp:Label></h2>
<asp:Label runat="server" ID="lblIdEmployee" Text="34343d-dfadfsf-3433"></asp:Label>
</div>
</td>
There is a blank space between the labels and I am trying to remove it.
Below a screenshot in design mode.
I want them to be together without any space in between.
How can I do this?
This happens by the fact that the 'h2' tag has its own browser-specific margin top/bottom style.
You can disable it something like this:
<h2 style="margin-top:0;margin-bottom:0;">...</h2>
<h2 style="margin-top:0;margin-bottom:0;"><asp:Label runat="server" ID="lblEmployeeFullname" Text="Claudie"></asp:Label></h2>
<asp:Label runat="server" ID="lblIdEmployee" Text="34343d-dfadfsf-3433"></asp:Label>

ASP.NET "To Bottom" hyperlink

On an aspx page I have following hyperlink:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="#Bottom" CssClass="ToBottom">To Bottom ↓</asp:HyperLink>
I would like to use it to navigate to the bottom of the page, more specificly, to an anchor with the name "Bottom":
<anchor name="Bottom" />
This doesn't work however... Any suggestions on how to make "To Bottom" and "To Upper" hyperlinks to quickly scroll through the page? Thanks.
**UPDATE:
A regular
To Bottom ↓
Doesn't work either.
This ought to do the trick:
To Bottom ↓
<a name="Bottom" />
I'd recommend using a regular anchor elment for this, there's no use for a server control:
To Bottom
This will work (using href property):
<asp:HyperLink href="#Bottom" runat="server" CssClass="ToBottom">To Bottom</asp:HyperLink>
and building an anchor like:
<a name="Bottom"></a>

asp.net datalist - change styling

<asp:DataList ID="ItemsList" RepeatDirection="Vertical" runat="server">
<ItemTemplate>
<asp:LinkButton
ID="SecondLevelItem" runat="server" CommandName="second"
OnCommand="SecondLevelItem_Onclick" CommandArgument="<%# Container.DataItem %>"
Text="<%# Container.DataItem %>" >
</asp:LinkButton>
</ItemTemplate>
</asp:DataList>
everything works fine. except that I do not have any control over the styling on the items. I mean I have the styling on the datalist externally but I want to add some spacing (vertically) between each item. How do I do tht? Thanks
In general, to control style, you can apply the <ItemStyle> tag inside the <asp:DataList>.
You can optionally inject CSS properties into the asp:LinkButton tag, either with the class attribute or directly with style, controlling the height or other CSS properties.
If it's applicable, you can still add a on the bottom of the template (but this will add a vertical space to the last item too, and I don't know if you want it).
Hope to have been of help.
In the code behind databound method for the list, you may be able to add a css class via the attributes collection.
In fact you may be able to that declartively too, just checking now...
eg asp:DataList id="blah" runat="server" ItemStyle-CssClass="someClass"

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>

Display/Hide part of a list

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.

Resources