views:

78

answers:

1

I'm trying to figure out a logical and quick way to implement the "PRG" design style in a small site I'm doing, and I'm finding an issue I can't think of a good way to solve.

I have a form. It has 2 fields (first and last name). When the user submits the form, I check to make sure that they have data in them before I save it to the database. If they do not, then I show them a nice little error message and leave what little they have entered still in the form.

However, in order to correctly implement PRG, as I understand it, I would have to validate on postback, determine there is an error, then redirect the user to the same page but via get, not post, which would then eliminate any kind of scary message "you are about to resubmit the contents of a form to the server, which can have unintended consequences..." etc if the user reloaded the page.

How can I redirect the user back to the same page and still save their already entered values in the form fields?

I mean, I could pass all the values in the Querystring, but for complex forms this would become very difficult and messy. I could store the values in Session, but that would still be messy, and a good way to bring a webserver to its knees on a busy site.

What do you, my fellow web programmers, do?

+1  A: 

As you note, by redirecting, you will lose the data they have entered unless you go through some QueryString gyrations. You are really defeating one of the nice features of asp.net by doing this - the form values are all preserved for you, so that if the page needs to be redisplayed after a post with errors, most of the work is done for you. Why do you want to use a PRG design? What benefit do you expect to get that standard asp.net form handling doesn't give you?

Ray
I'm really just playing around with PRG on a tiny little project to see what kinds of tradeoffs we have. So far, it's all fine, but this problem with losing the data they have entered is a pretty darn big strike against it.
Matt Dawdy
Yeah - you might as well go back to classic ASP pages :)
Ray
I think I just threw up in my mouth a little.
Matt Dawdy