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
Related
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.
I'm using ASP.NET MVC & CKEditor (Basic) to get input (almost exactly like this stack overflow RTE.) User's are limited to bold,italic,links.
I'm assuming I need to validate this server-side, incase someone issues CURL requests to my controller with any desired HTML in it. (I.E so they weren't limited by client-side validation).
So I need to allow, bold, italic, link tags, lists, but absolutely nothing else, how can this be achieved? I'll have a custom validator on my view model, but what is the best way to structure this custom validator? What to look for etc?
This could be achieved through regex and negative lookahead.
Something like that <(?!br/|br /|a|/a|strong|/strong|b|/b|i|/i|ul|/ul|li|/li>).+?> would match all tags except <br />, <a></a>, <strong></strong>, <b></b>, <i></i>, <ul></ul>, and <li></li>.
Then you could replace the matched occurences with an empty string.
For example this input (tested on regextester.com) :
test test link
Some <strong>text in bold</strong> and <b>another one</b> but also something
in <i>italic</i>
<ul>
<li>Now</li>
<li>a list</li>
</ul>
<table>
<tr>
<td>And a table</td>
</tr>
</table>
<br />
<hr />
Would become :
test test link
Some <strong>text in bold</strong> and <b>another one</b> but also something
in <i>italic</i>
<ul>
<li>Now</li>
<li>a list</li>
</ul>
And a table
<br />
I'm trying to implement a search bar to filter dynamic content in jQuery mobile by first letter. I want to implement data-filter like this: http://jquerymobile.com/demos/1.0a4.1/docs/lists/docs-lists.html#../../docs/lists/lists-search-inset.html
Super easy to do. However, I have a minor problem throwing me off. All my content is dynamic. Each record being read is a new list. Because data-filters are used for lists, I have a search bar above each record. My .NET code for my output looks like this:
<asp:Repeater ID="Repeater27" runat="server" DataSourceID="SqlDataSource27">
<ItemTemplate>
<ul data-role="listview" data-inset="true" data-filter="true">
<li class="list-head"><strong><%# Eval("Name")%></strong></li>
<li class="list-body"><%# Eval("GrEmail")%></li>
<li class="list-body"><%# Eval("Telephone")%></li>
</ul>
</ItemTemplate>
</asp:Repeater>
Because I am using a Repeater to list my dynamic content, it too is repeating my filter. I have tried moving the filter outside of my repeated region, and this doesn't work. In addition, the filter has to be attached to the list it is reading to work anyway.
Is there a work around from using a repeater in .NET?
Or is there a workaround for filters?
Can data-filter work for collapsible-sets?
I'm open to any and all suggestions. I greatly appreciate any insight you may have to offer. This has got to be a common problem with implementing dynamic content on a site. I'm wondering how the jQuery mobile documentation did this??
Thoughts?
Only Li should be repeated !! :)
change it with
`
<ul data-role="listview" data-inset="true" data-filter="true">
<asp:Repeater ID="Repeater27" runat="server" DataSourceID="SqlDataSource27">
<ItemTemplate>
<li class="list-head"><strong><%# Eval("Name")%></strong></li>
<li class="list-body"><%# Eval("GrEmail")%></li>
<li class="list-body"><%# Eval("Telephone")%></li>
</ItemTemplate>
</asp:Repeater>
</ul>
`
The should be outside of the repeater. The remaining dynamic content should then be within only one set of tags.
Adding runat="server" is not rendering my server tags <%...%>
I have a masterpage with a few <li> for menu and since I have to set class=selected for the current page, I am using a little server tag to find the url and assign the particular class.
I have total of 10 <li> and not all menu is available to all types of user, I need to toggle few of the <li> if the user is not admin, so I have runat="server" added to them so I can set their visible=false through c#
Here is how it is at a glance:
<li runat="server" id="liBlog" class='<%= Request.Url.AbsoluteUri.EndsWith("/Blog") ? "selected" : "" %>'>Group Blog</li>
<li runat="server" id="liPoll" class='<%= Request.Url.AbsoluteUri.EndsWith("/Poll") ? "selected" : "" %>'>Poll</li>
<li id="liInvite" class='<%= Request.Url.AbsoluteUri.EndsWith("/Invite") ? "selected" : "" %>'>Invite</li>
<li id="liFavourite" class='<%= Request.Url.AbsoluteUri.Contains("/Favourite") ? "selected" : "" %>'>My Favourites</li>
The <li> without runat="server" works fine, when on correct page the source code shows class="selected" or class="" as appropriate, the other <li> used to work fine too, until I decided to add the runat="server".
Once I added that runat="server", the whole block of class="" is being sent out to the html page, its not processing the server tags at all! I right click on the html and look at the source, it's being rendered as:
<li id="ctl00_ctl00_ContentPlaceHolder1_liBlog" class="<%= Request.Url.AbsoluteUri.EndsWith("/Blog") ? "selected" : "" %>">Group Blog</li>
It's pouring out my server tags into the source code!
Why is this behaviour seen? How can I avoid it?
I looked up a lot of similar threads in here and there was nearly nothing in google, so made this, I dont think this is a duplicate question.
You can't use the <%= %> syntax inside the properties of tags that have the runat="server" attribute on them.
You either need to:
Set the properties via your code-behind
Create an Expression Builder (and part 2 and part 3) and use the <%$ %> syntax (note: these are links to stuff I wrote on my blog, so, beware the self link =)
for your requirement you can also use ASP.NET menu and XmlSiteMap to do the same thing.
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.