Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 11th, 2007, 01:51 PM
Authorized User
 
Join Date: Dec 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help binding RadioButtonList

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?


 
Old May 11th, 2007, 01:58 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

This is by design. It prevents people from injecting HTML, JavaScript and any other potentially dangerous code into your script.

You can turn this off, however, your site will be less secure because of it.

in your global.asax file in the <system.web> add this: <pages ValidateRequest="false" /> this is a SITE wide change, if you only need the functionality on one page add this to your <%Page ...%> directive:

ValidateRequest="false"

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 11th, 2007, 02:16 PM
Authorized User
 
Join Date: Dec 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, I understand that now, but my problem is that the items of the RadioList's are not having the values binded to them... I tried this also, but no luck.

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

        radiolist1.DataSource = pics
        radiolist1.DataBind()

 
Old May 11th, 2007, 02:22 PM
Authorized User
 
Join Date: Dec 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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()

 
Old May 11th, 2007, 05:51 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Well.

Doing this: radiolist1.Items.Add(New ListItem(html, value))
defeates doing this:
'radiolist1.DataSource = pics
'radiolist1.DataBind()

Which I assume you figured out since your second example has the lines commented out. Have you resolved the problem?


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
Technical Editor for: Professional Search Engine Optimization with ASP.NET
http://www.wiley.com/WileyCDA/WileyT...470131470.html
================================================== =========
Why can't Programmers, program??
http://www.codinghorror.com/blog/archives/000781.html
================================================== =========
 
Old May 11th, 2007, 06:12 PM
Authorized User
 
Join Date: Dec 2006
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes works like a charm! Now I need help with my second topic, I posted a while ago.

Thanks!






Similar Threads
Thread Thread Starter Forum Replies Last Post
RadioButtonList sumith ASP.NET 2.0 Basics 0 October 2nd, 2007 11:30 PM
Get values from RadioButtonList debjanib ASP.NET 1.0 and 1.1 Basics 1 May 30th, 2006 09:45 PM
get values from radiobuttonlist debjanib ASP.NET 1.0 and 1.1 Professional 1 May 30th, 2006 09:36 PM
radiobuttonlist fzilz VS.NET 2002/2003 1 April 9th, 2004 10:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.