Solved

How to maintain Listbox position after Postback

Posted on 2007-12-03
5
805 Views
Last Modified: 2012-06-21
Greetings

I have a listbox that contains names. AT this point all I want to do si display the current item in a text box.

As I understand things (which stands a fair chance of being wrong!!), in order to see the change effected to the textbox, the AutoPostBack property must be set to TRUE, to foirce a PostBack after selection change. This I have done, but am getting the following:

A potentially dangerous Request.Form value was detected from the client (TextBox1="...>>Mickey<<<PL").

WHAT SHOULD I BE DOING??
(IT ALSO LOOKS LIKE THE POSITION IN THE LISTBOX IS BEING LOST ON POSTBACK!!)

My code:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            ListBox1.Items.Add("Mickey");
            ListBox1.Items.Add("Donald");
            ListBox1.Items.Add("Goofy");
            ListBox1.Items.Add("Wacko");
            ListBox1.SelectedIndex = 0;
        }
       
        TextBox1.Text = ">>>" + ListBox1.SelectedValue + "<<<PL";
    }
   
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = ">>>" + ListBox1.SelectedValue + "<<<SI";
    }
    protected void ListBox1_TextChanged(object sender, EventArgs e)
    {
        Label1.Text = ">>>" + ListBox1.SelectedValue + "<<<ST";
    }

In advance, thanks!!
0
Comment
Question by:allanmark
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 37

Accepted Solution

by:
samtran0331 earned 300 total points
ID: 20395715
>>A potentially dangerous Request.Form value was detected from the client

this is happening because .Net detects that the textbox contains the "<" and the ">" characters....which can be used for sql/script injection attacks.

while you can turn the warning off, you lose a level of hack protection.
0
 
LVL 14

Assisted Solution

by:Dustin Hopkins
Dustin Hopkins earned 75 total points
ID: 20395757
You could use the html encoded values for >(&gt;) and <(&lt;) in your code.

Label1.Text = "&gt;&gt;&gt;" + ListBox1.SelectedValue  + "&lt;&lt;&lt;PL";

Open in new window

0
 
LVL 37

Assisted Solution

by:samtran0331
samtran0331 earned 300 total points
ID: 20395802
that would work for a label, but .Net is catching the tags when the code does this:

TextBox1.Text = ">>>" + ListBox1.SelectedValue + "<<<PL";

and setting a textbox text to "&gt;" will still render "&gt;"
0
 

Author Comment

by:allanmark
ID: 20396170
Short and sweet  -  Thank You very much!!!
0
 

Author Closing Comment

by:allanmark
ID: 31412334
Most educational -  thank you!!
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question