?
Solved

How to maintain Listbox position after Postback

Posted on 2007-12-03
5
Medium Priority
?
813 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 1200 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 300 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 1200 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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.…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 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