I have a list in asp.net like this:
<ul id="menu" runat="server">
<li class="theMenu">Menu 1</li>
<li class="theMenu">Menu 2</li>
<li class="theMenu">Menu 3</li>
<li class="theMenu">Menu 4</li>
</ul>
I want to add a class to a list item when it is clicked using VB.net. So the user can see what menu item is the "active one" Just like it is done using jQuery:
$(".theMenu").click(function() {
$(this).addClass("Active");
});
How do you do this using VB.net???
Just use the jQuery. Really. Doing this from VB.Net means you have to cause a PostBack, and that means completely re-creating your page on the server. You don't want to do that more than you have to. It adds load to your server, and adds latency to your page responses.
I suspect you also want to know later on which item is marked as active, so I also suggest combining this with an <asp:HiddenField> control, and add a line to the jQuery to also set the value of the hidden input created by the control. Later on, when you need to know in VB.Net which list item was marked as active, you can just check the Hidden Field.
Related
When creating a standard asp.net web site with vs2013 I notice that no site map is used and I also note that the menu created is a new nav bar class.
You get this as a default:
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li><a runat="server" href="~/">Home</a></li>
<li><a runat="server" href="~/About">About</a></li>
<li><a runat="server" href="~/Contact">Contact</a></li>
<li><a runat="server" href="~/Upload">Upload Files</a></li>
<li><a runat="server" href="~/Portal/UploadCust">Customer Portal</a></li>
</ul>
So, no site map is used here. And the menu system in asp.net NOW does not use the site.map. What is the suggested approach NOW THAT NO SITEMAP is used in these templates to hide a given menu based on role?
Is the suggestion to create a sitemap by hand? and then simply enable trimming as was done in the past? I have role permissions working fine (sql providers) but I am perplexed why this new menu system does not support nor have anything to do with site maps? I am simply looking to hide menu options based on role membership but am at a loss as to why the default menu systems don't use sitemap anymore? Right now users just get a 404 error.
So is some suggested way to hide menu options in above or is it still best to adopt a site map and enable trimming? This being the case then must I drop use of the above new nav bar class?
edit:my current solution is to add a id like this
"<a id="PortalLink" runat="server" href="~/Portal/UploadCust">Customer Portal</a>
And then in the web site on-load in VB, I use this:
If Roles.IsUserInRole("Portal") Then
Me.PortalLink.Visible = True
Else
Me.PortalLink.Visible = False
End If
I need to create a custom control that spits out the the following html:
<ul>
<li>
link button
</li>
<li>
link button
</li>
</ul>
I need the links to be LinkButtons and output inside the li elements.
What is the best way of going about building this control?
You can do that using built-in DataBound Controls like ListView Or Repeater controls.
You can add LinkButton within the li tags.
Other resources:
http://www.asp.net/aspnet-35/videos/the-listview-control
I am using ckeditor to save my texts... (asp.net mvc)
In the database the text are stored like this:
<ul><li>List item</li><li>List item</li><li>List item</li></ul>
And when I am running my website I want it look like this:
List item
List item
List item
But the text are the same as in the database:
<ul><li>List item</li><li>List item</li><li>List item</li></ul>
And the source code are:
<ul>
<li>
List item</li>
<li>
List item</li>
<li>
List item</li>
</ul>
What am I missing?
Your text is being HTML encoded, if for example you're using <%: Prop %> this will happen, if you want it to render exactly, you want <%= Prop %>. There are a dozens of ways to get HTML into a page so I'm not sure exactly which method you're taking, but whichever way it is, it's passing through the Html encoder along the way.
Keep in mind storing the text and displaying it like this does render your site vulnerable to cross-site scripting and other attacks, so you will probably want to sanitize the incoming HTML.
Try using Server.HtmlDecode:
http://msdn.microsoft.com/en-us/library/hwzhtkke.aspx
What is the quickest way to test validity of any xhtml css code snippet (not whole page} in W3C validator? and give link of that test in forum/question/discussion.
code snippet like this
<ul>
<li>Item one</li>
<li>Item two</li>
<li>Watch, you can easily nest list items: This item has some sub-items</li>
<ul>
<li>Sub-item one</li>
<li>Sub-item two</li>
<li>Shall we do a 3rd nested list?</li>
<ul>
<li>OK</li>
<li>Your browser should automatically use different bullet styles for each level.</li>
</ul>
</ul>
</ul>
Look at the extra options in the validator, there is one to validate a HTML fragment. Bookmark this to jump straight to it: http://validator.w3.org/#validate_by_input+with_options
You can't post a link to the validation output, because validating by direct input uses POST (through form submit), not GET (though URL). The only way to "share" the validation is to validate by URI.
You could keep a "template" HTML file on your computer with a doctype and <body> tag (look at what the fragment validation I mentioned above adds to your code), upload that file to a folder in your web space and share the validation link for that.
I am using jquery tabs(First,Second,Third) in multiple asp.net pages (First.aspx, second.aspx,Third.aspx) in my asp.net website and in each page i am writing the ul,li code.
For example in the First.aspx page I am writing the following code inside the 'ul' tag
<li class="current">First tab</li>
<li>Second tab</li>
<li>Third tab</li>
Similarly in the second.aspx,Third.aspx pages i am using the Class="current" to highlight the selected tab.Recently we have planned to move to Master pages.So the master page should contain the ul,li code for the tabs.But the problem is that I do not understand how to apply the class="current" to the selected tab,in the case of the master page.Could someone please help?
Thanks in advance.
Write a javascript function in your master page to set the current class on a tab. Each page can then call that function when it's loaded to set the current page.
Something like:
<li id='tab1'>First tab</li>
<li id='tab2'>Second tab</li>
<li id='tab3'>Third tab</li>
function setCurrentTab(selectedTab) {
$('li').removeClass('selected');
$('[id=selectedTab]').addClass('selected');
}
and in Second.aspx, for example:
setCurrentTab('tab2');