Need help binding RadioButtonList

Discussion in 'C#' started by binici, May 11, 2007.

  1. #1
    Hello all:

    I am trying to have an array of images in a RadioButtonList, which is working, but I need to set the values (Image file names) to each item within the RadioButtonList, but I am having some difficulties.

    I have this so far:

    ASPX:

    <

    asp:RadioButtonList ID="radiolist1" runat="server" AutoPostBack="true" CellPadding="4" CellSpacing="0" RepeatDirection="Horizontal" RepeatLayout="Table"></asp:RadioButtonList>
    VB:

    Const

    IMAGE_DIRECTORY As String = "/homepage/Images/Articles/"

    Dim pics As ArrayList = New ArrayList()

    Dim s As String, html As String

    Dim value As String

    For Each s In Directory.GetFiles(Server.MapPath(IMAGE_DIRECTORY), "*.jpg")
    html =

    "<img width=50 height=50 src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """>"
    value = Path.GetFileName(s)

    pics.Add(html)


    Next
    radiolist1.DataSource = pics

    radiolist1.DataBind()

    radiolist1.Items.Item(0).Value = value

    I have that in the Sub Page_Load.

    When I set the RadioButtonList with the

    SelectedIndexChanged event, I get an error message:



    A potentially dangerous Request.Form value was detected from the client (radiolist1="<img width=50 height...").
    How can I set the value for each RadioButtonList with the file name?
     
    binici, May 11, 2007 IP
  2. binici

    binici Peon

    Messages:
    22
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If (Not Page.IsPostBack) Then
    Const IMAGE_DIRECTORY As String = "/homepage/Images/Articles/"
    'Dim pics As ArrayList = New ArrayList()
    Dim s As String, html As String
    Dim value As String

    For Each s In Directory.GetFiles(Server.MapPath(IMAGE_DIRECTORY), "*.jpg")
    html = "<img width=50 height=50 src=""" & IMAGE_DIRECTORY & Path.GetFileName(s) & """>"
    value = Path.GetFileName(s)
    radiolist1.Items.Add(New ListItem(html, value))
    'pics.Add(html)
    Next
    End If

    'radiolist1.DataSource = pics
    'radiolist1.DataBind()
     
    binici, May 11, 2007 IP
  3. ccoonen

    ccoonen Well-Known Member

    Messages:
    1,606
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    160
    #3
    yes, it's throwing an error because it's posting back what it sees as a hack attempt or XSS or SQL Insertion attempt. you will have to spoof it or display data in a different manner rather than posting back the physical HTML.
     
    ccoonen, Jun 8, 2007 IP