I have an XML file storing a string like the following:
Error: The form's name field was left empty!
Now, this message in the XML file is used in various locations. For instance, it is sometimes bound to an aspx control and sometimes displayed in a JavaScript alert.
In order to escape the single quote character, I modified the message as follows:
Error: The form\'s name field was left empty!
When the message is shown in a JavaScript alert, it is displayed as it should with the single quote escaped. However, when it is bound to an aspx control, it is displayed as is.
I tried modifying the message as follows:
Error: The form's name field was left empty!
and
Error: The form‘s name field was left empty!
With these two cases, the message displays as it should when bound to an asp control. However, when passed to a JavaScript alert, I get the ") expected" error in IE8.
How can I get this to work for both aspx controls and JavaScript alerts please? I have already wasted a lot of time on it. Thank you so much.
N.B. I am using a very old version of the .NET Framework, specifically 2.0.
You should just store your messages verbatim and then let each client handle the special character. So, store as Error: The form's name field was left empty! and then within each language add a step that checks for special characters and escapes them accordingly.
Related
I've encountered a problem with html special character conversion when the jqxeditor is bound to a model for the message. Once that model is saved the partial view is reloaded and any greater then or less than symbol is not displayed, but rather <>
This happens whether the data is changed to <> or left html. The original text area shows < > when it does not have the jqxeditor applied to it.
I saw a problem similar to this at:
How to stop converting “greater than” and “less than” symbols to entities in Rich Text Editor?
I've also tried loading the value through javascript val, instead of automatically binding it using asp-for
The work around I found was to replace the   & < > on the controller that accepts the form post and put. Those values are stored with html markup for everything else except the specified characters in the database, which is in turn given to the jqxeditor without indicating special characters. Also, the message displays with no issue when the message is viewed.
So far, so good. However, I'd rather have the jqxeditor display those characters from the HTML markup when loaded either from the model or from javascript.
What am I missing?
I'm making a detail page about certain items.
This detail page can contain large blocks of text, and the customer would like to only show the first 100 letters and then put a " ... more " at the end.
When the user clicks this " ... more " the rest of the text can be shown.
Biggest problem: the text is currently is a CMS and has large varieties. Some is pure text, some have html elements in them ...
I tried to cut off the text and put them in spans. Then i could show/hide these spans as i please. The issue here is that there can be a starting element of a certain tag in the first span and the closing element can be in the second span. This causes the DOM hierarchyto be faulty and the result is never pretty.
Does anyone know a ( other ) way to achieve this or a library i can use ?
To be able to extract "readable" characters you need to get the content into a plain text format (get rid of the mark-up).
Since the content is stored in a cms it is likely that the content is structured to be well formed - thus xhtml.
If that is the case you can treat the content as XML. Get the root node and get the innertext property there-of. Then you will have plain text - no tags - and can easily cut it after the first 100 characters or whatever the requirement is.
Hopefully the content doesn't contain js/css!
Edit:
It seems that the markup must be retained.
Try the following xsl to transform and truncate the content:
https://gist.github.com/allen/65817
I am new to C# and was experimenting with the ASP.Net GridView (framework 3.5), and I found out a big problem when the gridView text contains the following:
ñ/Ñ/á/Á/é/É/í/Í/ó/Ó/ú/Ú or a â, ê, î, ô, û, ë, ï, ü or even a ç
The results end up displaying something like this: &+#+237
I made a mixture of pain by doing a table,dataset etc... to get the data from the database clean as the letter itself. I also tried making a method that cleaned the variables but it was a terrible IF.
I was wondering if there was a way to make the letters appear as themselves (ñ as ñ not as &+#+237) when extracting data from the gridview without getting the data directly from the database and without doing a lot of code. If there is not, is there a way to code efficiently clean them up?
Your characters are being HTML encoded, either somewhere in your data access layer, or within the gridview controls. Try running the text through HttpUtility.HtmlDecode() before binding the grid.
If that doesn't work, then it's probably being encoded at the control level. I see that you tagged this question with "textbox". The standard ASP.NET TextBox control will automatically encode anything that's assigned to its Text property. Instead, you can use a generic System.Web.UI.HtmlControls.HtmlTextArea control or new HtmlGenericControl("input").
I'm making a contact page so user's can send message to me when they want.
I got a textbox that they can put thire name, and regular expression to check if the name is in the correct form.
[אבגדהוזחטיכלמנסעפצקרשתץףןם\s\.]
My problem is that when I enter hebrew characters into the textbox its still don't recognize it and I get a validation error.
I tried the same regualr expression with an English unicode [a-zA-Z] and it work.
Do I need to add somthing to the .aspx page so it will "understand" that the input is in different language?
Perhaps the problem is that you only allow one character with your regular expression?
Try to change it to
[אבגדהוזחטיכלמנסעפצקרשתץףןם\s\.]*
Apart from that, I don´t think that you need to add any culture info to the page.
I'm quite new to this:
I have created a simple form which contains a textbox and button and basically when the email address entered is correct, some results are shown below (this is using a gridview control).
What I am wanting to do is have some sort of email validation for the form - but have the validation placed within the page_load (within the button click) rather than the code behind the page itself.
I'm after a simple validation that checks an email has been entered otherwise display a popup and the email format is correct (abc#abc.com) in C#
I assume that the details will be displayed only when the buton is clicked ( form submitted) if so why not add a RegularExpression validator and map it to the text box. Then use the following regular expression to validate an email.
\b[A-Z0-9._%+-]+#[A-Z0-9.-]+\.[A-Z]{2,4}\b
This way it will increase user experience as well. The user does not have to wait for a post back to get the error alert.
Another regular expression for email format validation here.
This has been covered here.
Problem is there is no valid regex that covers the whole RFC 5322 grammar. All common regexes (like the one stated by Shoban) are too strict - example: the end part [A-Z]{2,4} that is supposed to cover the top level domain will tag .museum emails as invalid; but there are much more complex examples, like German Umlauts (vowel mutations) that have been allowed not too recently.
Our approach is to check for a superset rather than a subset of allowed emails in validation controls (like the one integrated integrated in Visual Studio that uses \w+([-+.']\w+)#\w+([-.]\w+).\w+([-.]\w+)* ) and deepen the check back on the server (maybe even use a webservice, like this one.
BTW, here is a better regex.