I am storing "<script>alert("Hello")</script>" in the database and when i try to display the content in a Label it shows alert in the web page how can I solve this.
(1) Don't use a label, use a Literal control and set the mode to "Encode", so your tags will be HTML encoded: See: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.literal.mode.aspx.
Or
(2). Say: label.Text = HttpUtility.HtmlEncode(stringFromDataBase);
(3): Edit: I should also mention, you can use the code nugget: <%: which will html encode the text. It's the same as <%=, except, the output is HTML encoded. Very handy. Example: Welcome: <%: UserName %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With