1

I am using asp.net 3.5 (codebehind c#). My users are running IE 7 or 8. I have a data entry page with several TextBoxes.

When I want to clear the all the TextBoxes, I do a sever.transfer back to the same page.

Maybe 99% of the time, this clears the TextBoxes. Every so often it does not.

I know that a roundtrip to the server has happened because:

  • The dropdown lists and radiobuttonlists on the page get reset, and
  • DB processing happened as shown by a record having been saved to the DB.

The inconsistency is confusing me.

What could be causing the TextBoxes to persist data in this way and how can I prevent it from ever happening?

It is resulting in users saving the same data twice.

I don't think this would have anything to do with it, but there are also various js functions on the page for validation, capitalizing the first letter of an input, etc

Marcel
  • 15,039
  • 20
  • 92
  • 150
Lill Lansey
  • 4,775
  • 13
  • 55
  • 77
  • 1
    Are you able to reproduce this behavior on "clean" IE installations, i.e. installations where people don't have any add-in's. There are add-ins that "save" your form data to help save time refilling forms. – CodingGorilla Jul 16 '12 at 14:33
  • I am not able to reproduce this behavior at all. That is the problem. However, I will check the machines that are being used to see if they have any add ins. Can you suggest some add ins to look for? Even if there are addins, why would they only cuse this to happen about 1% of the time? – Lill Lansey Jul 16 '12 at 14:38
  • The one that I personally use is LastPass, https://lastpass.com – CodingGorilla Jul 16 '12 at 14:40
  • Even if there are addins, why would they only cause this to happen about 1% of the time? – Lill Lansey Jul 16 '12 at 14:45
  • Well I guess that's the next question, if you find users with addins like this, are they able to reproduce it consistently. It's all part of troubleshooting, I'm just trying to offer ideas that you can look at. In the end, this is most likey a browser issue and has absolutely nothing to do with your code, unless your code is refilling the TB's from a cookie or view state or something. – CodingGorilla Jul 16 '12 at 14:49
  • 1
    Why are you doing a Server.Transfer? You should probably do a Response.Redirect instead. – Kevin Main Jul 16 '12 at 15:04
  • 1
    @kevin - One less page call with Server.Transfer? – Lill Lansey Jul 16 '12 at 15:56
  • @LillLansey You might want to read the answer to this question http://stackoverflow.com/a/4862741/1191903 that explains what Server.Transfer does vs Response.Redirect - I would guess this is the cause of your issues. – Kevin Main Jul 17 '12 at 12:05

1 Answers1

2

As this MSDN article describes the Server.Transfer method, this is probably not the right way to empty the TextBoxes. The method explicitly keeps all state information.

A better approach is described within this answer:

foreach (var item in Page.Controls)
        {
            if (item is TextBox)
            {
                ((TextBox)item).Text = "";
            }
        }

You will keep the roundtrips to just one, and you could keep all other user inputs as they were, if you like.

Community
  • 1
  • 1
Marcel
  • 15,039
  • 20
  • 92
  • 150