Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1017861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:46:11+00:00 2026-05-16T10:46:11+00:00

I have a webform with a a couple of boundfields in an edit window

  • 0

I have a webform with a a couple of boundfields in an edit window as follows:

<asp:BoundField DataField="TS_TITLE" HeaderText="Title" SortExpression="TS_TITLE" HeaderStyle-VerticalAlign="Top" HtmlEncode="True" >
            <ControlStyle Width="500px" />
        </asp:BoundField>
        <custom:BoundTextBoxField DataField="TS_DESCRIPTION" HeaderText="Desription" HeaderStyle-VerticalAlign="Top" SortExpression="TS_DESCRIPTION"
            TextMode="MultiLine" Rows="20" Columns="100" Wrap="True" HtmlEncode="True"  />

I’m using the Html Encode property of the BoundField to secure against cross-site scripting attacks. What I would like to do is when a user reopens the edit window, I want the encoded html to be decoded and presented, html tags and all. My problem is that when I try to decode the html in the code-behind, under the Page_Load function, it doesn’t get set when the page is presented to the user, i.e. it has no effect. Here is the snippet of code from the Page_Load:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Dim dvrTest As DetailsViewRowCollection = DetailsView1.Rows

        Dim DescriptionTB As TextBox = dvrTest.Item(1).Cells(1).Controls(0)
        DescriptionTB.Text = HttpUtility.HtmlDecode(DescriptionTB.Text)
    End Sub 'Page_Load

When debugging I can see the html decoded text as it should look, my guess is that there’s an additional databind that occurs after the Page_Load exits that resets the BoundTextBoxField. Just a note, I’ve tested this on both the BoundField and BoundTextBoxField and the effect is the same on both.

I had a similar issue with a dropdown list I’m using in another part of my application, only there I was using the onLoad event to call a function to do data manipulation after the page was loaded and databound. Unfortunately, Boundfield doesn’t seem to have that event, the closest thing I’ve found is DataFormatString property, but that only seems to be useful when working with dates and currency.

UPDATE:

In case anyone was wondering, even with the HTMLEncode property set to false, I get the encoded text when the Edit Window is Reloaded.

UPDATE 2:

Tried overriding the OnDataBinding method, but that didn’t seem to do anything.

Protected Overrides Sub OnDataBinding(ByVal e As System.EventArgs)
        Me.OnDataBinding(e)
        Dim dvrTest As DetailsViewRowCollection = DetailsView1.Rows
        Dim DescriptionTB As TextBox = dvrTest.Item(1).Cells(1).Controls(0)
        DescriptionTB.Text = HttpUtility.HtmlDecode(DescriptionTB.Text)
    End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T10:46:12+00:00Added an answer on May 16, 2026 at 10:46 am

    Got it. Since my boundfields were encased in a DetailsView, I used the onLoad event of the DetailsView to call a function in the code-behind to decode the any html within the text of the Boundfields

    ''' <summary>
    ''' Decodes any HTML formatted tags in the Title and Description Textboxes of the Edit Window
    ''' </summary>
    ''' <param name="sender"></param>
    ''' <param name="e"></param>
    ''' <remarks></remarks>
    Protected Sub HTMLDecode(ByVal sender As Object, ByVal e As System.EventArgs)
        If Page.IsPostBack = False Then
            ''Grab the Title and Description text boxes from the RowCollection
            Dim dvrTest As DetailsViewRowCollection = DetailsView1.Rows
            Dim TitleTB As TextBox = dvrTest.Item(0).Cells(1).Controls(0)
            Dim DescriptionTB As TextBox = dvrTest.Item(1).Cells(1).Controls(0)
            ''Decode HTML tags that are in either text box
            DescriptionTB.Text = HttpUtility.HtmlDecode(DescriptionTB.Text)
            TitleTB.Text = HttpUtility.HtmlDecode(TitleTB.Text)
        End If
    End Sub 'HTMLDecode
    

    And calling it in the DetailsView using the onLoad event

    <asp:DetailsView ID="DetailsView1" runat="server" Height="260px" Width="500px" AutoGenerateRows="False"
                DataKeyNames="TS_ID" DataSourceID="SqlDataSource2" EnableModelValidation="true"
                GridLines="Both" Font-Names="Arial" HorizontalAlign="Center" OnLoad="HTMLDecode" >
    

    If there are any more straightforward alternatives, I’d be glad to hear them.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

On my C# asp.net webform I have a search page that has roughly 20
We have a pretty big ASP.NET WebForm (web application) project with a lot of
I have a simple webform that will allow unauthenticated users to input their information,
I have the following webform: <%@ Page Language=C# AutoEventWireup=true CodeBehind=Default.aspx.cs Inherits=TestWebApp.Default %> <!DOCTYPE html
I have a .NET webform that has a file upload control that is tied
I have a webform gridview. In that one columns is password. I want to
I have a web form that binds a DataGrid to a, normally, different data
I have a web form that has multiple ListBoxes, TextBoxes, DropDowns. If I put
I have a web form that I am attempting to implement dynamic drop down
Say you have a web form with some fields that you want to validate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.