.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Literal control decoded text & XSS attack

Posted By:      Posted Date: October 16, 2010    Points: 0   Category :ASP.Net

Hi all-

I have a FreeTextBox editor set up on a page for clients to HTML format the data they enter.  I collect the data, encode it and save it to the DB.  Upon retrieval, I decode it and display it in a literal control. 

Everything I'm reading to prevent an XSS attack says it should be encoded in the literal control.  But if I do that, the data won't display how the client formatted it - it displays as encoded text.

So, how do I show the formatted data (html) in the literal control and prevent a XSS attack at the same time?

View Complete Post

More Related Resource Links

Customize failure text for login control


Hi all,

I would like to show the failure text in a client-side alert box for login control in c#. Please help me if there is an easy way to convert it from vb.net to c#.net. Thanks a lot!

Protected Sub Login1_LoginError(ByVal sender As Object, ByVal e As System.EventArgs) Handles Login1.LoginError
'Display the failure message in a client-side alert box
ClientScript.RegisterStartupScript(Me.GetType(), "LoginError", _
String.Format("alert('{0}');", Login1.FailureText.Replace("'", "\'")), True)

 End Sub

 Converted, but it doesn't work.

protected void Login1_LoginError(object sender, System.EventArgs e)
    //Display the failure message in a client-side alert box
    ClientScript.RegisterStartupScript(this.GetType(), "LoginError", string.Format("alert('{0}');", Login1.FailureText.Replace("'", "\\'")), true);

how to get the text of selected checkbox from asp.net checkboxlist control using jquery


I have asp.net checkboxlist control that bounded to a data source so the number of items in the control are different from one to to another time.

I have this function:

     $('#<%=chkListGroups.ClientID %> input:checkbox:checked').siblings('label').text();

this function will return all texts for all selected items in the control as a one string.

 I'm looking for a way that when I check a check box from the ckeckboxlist control will return only last checked checkbox.

this code :

$('#<%=chkListGroups.ClientID %> input:checkbox:checked').last().siblings('label').text(); 

returns last checked item for example if I checked second will return
second item then when I checked fifth item will return fifth item but
if now when I check third item will return fifth item so it is always
returning last item checked in the list and I'm looking to

Please advice me how to do this using jquery.

Want to Create Table Dynamically With text Control in WinForm Csharp

Hello To All... from Many Days i m tryng to create a simple table using csharp in WinForm.Which will include textbox in each cell according the Passed No of Col & Row. but not getting the proper result. Actually i want to trace each cell data and want to save each cell data to data base : eg. in cell 11(1col & 1row) i m having Combobox which having some item list and when the user select the list item the data will save to the database. Regards, Praveen    What is the Key of Life ... Its Sharing Your Thought & Knowledge ...

How to control the text and other properties in ResourceDictionary object that i wrote ?

I wrote some ResourceDictionary. This ResourceDictionary is actuly a button that i use - I created this button by using Rectangle and TextBlock ==> that mean that the my xaml look like the code below. The problem is that i cant change the font size and the text of the TextBlock. I can change is just from the xaml of the template. And ... How can i define some variable that will control on the rectAngle redius in runtime ? Someone can help ?? ? Thanks. ...<ResourceDictionary> <Style x:Key="MyBtn" TargetType="{x:Type Button}"> <Rectangle ... <TextBlock.... </ResourceDictionary> ...

Problems with control

Hi thereI am currently helping out with a website and we are using literals to display images. This works fine in Internet Explorer but as soon as I run it in google chrome the images do not load. The following is the code using linq to sql & MVVM to pull the information out the database. Any Assistance would be appreciated. phWomen is the name of the literalStringBuilder sb = new StringBuilder();             foreach (WomenViewModel wvm in Women)             {                 sb.Append("<a href='_Portfolio.aspx?ID=" + wvm.Women.WomenID.ToString() + "'><img alt='' border='0' height='152' width='238' src='Content.aspx?ItemID=" + wvm.Women.WomenID.ToString() + "&ItemName=womanmainphoto'/></a>");                              }             phWomen.Text = sb.ToString();StringBuilder sb = new StringBuilder();foreach (WomenViewModel wvm in Women){           sb.Append("<a href='_Portfolio.aspx?ID=" + wvm.Women.WomenID.ToString() + "'><img alt='' border='0' height='152' w

Creating mixed logo and text scrolling control

Hello I have a scrolling control that I use for text.   After a while, I switched to a picture combining the text messages and a logo in between.  So the process became: 1. Get message. 2. Get logo. 3. Create a picture of the text messages and the logo in between. 4. Scroll the picture. All was in the plain C# language.   My question is if I can do the same with WPF without creating a picture?   Thanks Eli

Tab Panel inside a User control - null referance to text box with set properties

Hi guys, Im having problems with the following: I have a user control which has a tabbed panel inside, I then have a public property which populates a textbox inside the tabbed panel, HOWEVER when I access the property on my ASPX page, it give me a null referance to textbox, I have tried using findControl but still finds nothing, Please help!! ASPX PAGE  <Registration:UserDetails UserID="23" ID="RegistrationUserDetails" runat="server" /> USER CONTROL<cc1:TabContainer ID="TabContainerRegistration" runat="server" ActiveTabIndex="1" > <cc1:TabPanel runat="server" ID="TabPanelAccessDetails" HeaderText="Access details"> <ContentTemplate> <table> <tr> <td>User ID</td> </tr> <tr> <td><asp:TextBox ID="UserIDTextBox" ReadOnly="true" runat="server" SkinID="InputBoxes"></asp:TextBox></td> </tr> </table> </ContentTemplate> </cc1:TabPanel> </cc1:TabContainer> CODE BEHINDprivate int _UserID; public int UserID { set { TextBox tb = (TextBox)TabContainerRegistration.

Can not reference text value in footer of Gridview control


I have been struggling with this all week end .... Yell

I am trying to implement adding a new record using the Gridview footer.

I have an example that works finethat I got from http://www.aspdotnetcodes.com/GridView_Insert_Edit_Update_Delete.aspx.

My situation is a little different .. as I am using master page and the Gridview is in a page derived from the master page.

I have tried:

Dim txtNewName As TextBox = DirectCast(GridView1.FooterRow.FindControl("NewName"), TextBox)

"NewName" is the ID of the textbox in the footer of the Gridview.

When I try referencing ... txtNewName.Text ... it returns a null value.

There must be some trick to referencing this .Text value when using the Gridview that is within a Content Place Holder that results when using a page that was created using a master page.


Thanks in advance fo any possible help with this problem ...

Find the RootNode text/value of TreeView control using Javascript



Is it possible to find the text/value of the Rootnode  of Treeview control using javascript.



How to save a multiple user control to a few single record text?

I have a list with people pecker control that admits multiple users.
I like to have another list with one record for each user in the control that loaded before.
Is there any way in InfoPath or in a workflow to use something like FOR EACH to take one by one user in a control and write/update records after that?
Thank in advance

In a button's control template, how can I alter the color of a text block?


Using WPF 4, I'm trying to create a button style (that would preferably work in SL, as well) that alters the text color of any contained text when the button is mouseover'd. Since I'm trying to make this compatible with Silverlight, I'm using the visual state manager:

<Style TargetType="{x:Type Button}">
  <Setter Property="Template">
      <ControlTemplate TargetType="Button">
        <Border x:Name="outerBorder" CornerRadius="4" BorderThickness="1" BorderBrush="#FF757679">
            <VisualStateGroup x:Name="CommonStates">
              <VisualState x:Name="Normal" />
              <VisualState x:Name="MouseOver">
                  <ColorAnimation Duration="0" To="#FFFEFEFE"

Auto click Literal Control on Form Load


Hi Everyone,

          How can one Auto click a Literal Control button on Form Load???

How to set a link in Calendar Control and retain text in the control?


Hi Community

    This is my first time in this forum.

    I have a Calendar Control that I added text that show scheduled meetings on certain dates and it works okay.
The problem is that when I click on a date I need to http to another web page or sometimes goto a web page in
the same web site.  The problem is  when the code that  creates the hyperlink runs it replaces the text displaying "meetings"
scheduled for that date instead appending the link to the date and retaining the "meetings" text that was already there.

fyi, e.Day.Date.Day matches any number entered.

Below is how I set that up with the code that adds the meetings followed by the url code that replaces the meetings text: 

public partial class _Default : System.Web.UI.Page


string[,] vholidays = new

Wrapping Text (and not words) with the RichTextBox Control


Hi all,


What I am trying to do is create a RichTextBox control on my form. I want the RichTextBox control to only be able to contain 32 characters per line. I am using Courier New font, which is a fixed width font. I can set the width of the control so its long enough to show 32 characters, which works. The problem I am having is that after 32 characters, if I set the WordWrap property to true, it will wrap the last word. I do not want the last word to wrap. I simply want it to go to the next line. I do not want any carriage returns added to the code. I just, visually, want the control to jump to the next line, without wrapping any words. If I set WordWrap to false, then it doesn't wrap at all. it simply keeps going past 32 characters.


Does anyone know a way to make this control wrap text at 32 characters?

Rich text control of SharePoint in asp.net



I have created an ASP.NET page to access Sharepoint List (Win 2003, WSS 3.0). I am accessing connecting to the Sharepoint site through Sharepoint webservices.

ASP.NET site has a form with text boxes and when we press OK, we send this information to the richtext columns in the sharepoint list. Some times I need to format this text.

Question: Is there a control/script/method that can add the little formatting toolbox to these text boxes.


adding static text before Bind() in datalist control


Hello, I have a datalist control

In it, I have a hyperlink that im binding the url, and the text to from a mysql database

here is my code so far

<asp:HyperLink ID="HyperLink1" runat="server"
    NavigateUrl='<%#Bind("topicid") %>' Text='<%# Bind("title") %>'></asp:HyperLink>

Now, the problem is, the field "topicid" returns a number, such as 3. I want to add the following text before it: viewTopic.aspx?id=

So, ideally, i want something like this

<asp:HyperLink ID="HyperLink1" runat="server"
    NavigateUrl='<%# "viewTopic.aspx?id=" + Bind("topicid") %>' Text='<%# Bind("title") %>'></asp:HyperLink>

But, when I do it that way, I obviously get an error.

So, is there any way to solve this problem without having to modify the database?

Thank You

Updating a text within a div tag with textbox control.


Hello everyone, I have a question regarding to the text in the html code. I would like to know if there is a way to change the content text in the html with text that has been written in textbox. For example i have following text in html, so how can I replace this text by using a text box in the server side.


I will be grateful if someone gives me a little help. Thanks,

ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend