-1

I have several textboxesand dropdownlists on my form. When a user submits the form, I want to keep several of these values on the form but I also want to make them invisible for several seconds after the form submits, so the user knows the form has been submitted. I am pretty sure you need to do an autopostbackin order to change the visibility of textboxesand dropdownlists but I do not want to do an autopostback because I will lose the fields I want to keep. Any alternatives?

escobar_season
  • 113
  • 1
  • 3
  • 10
  • 3
    You don't lose values when `ViewState` is enabled (default). – Tim Schmelter Jul 17 '12 at 21:56
  • @TimSchmelter Wouldn't the value of a textbox be "control state" that can never be disabled? (Only manually cleared?) – millimoose Jul 17 '12 at 21:57
  • 1
    Have you tried anything? Can you show your code that doesn't work? – Mark Byers Jul 17 '12 at 22:00
  • *"but I also want to make them invisible for several seconds after the form submits, so the user knows the form has been submitted."* - Can you clarify this? I'm not sure I understand. If you're doing a standard form post, wouldn't the user know the form has been submitted simply by the refreshed page? You want to make them invisible when the page loads in response to a form post? Or are you using AJAX or something? When you say "invisible" do you just mean not display them to the user, or not render them at all to the output? There's a big difference. – David Jul 17 '12 at 22:06

1 Answers1

0

Can you please expand your question, give more light to what you're dealing with, right now it's very ambiguous.

As for making textboxes / dropdownlists "invisible" you can accomplish this through Javascript:

<input type=text id=text1>
<input type=button value=hide onclick=hide()>
<input type=button value=show onclick=show()>
<script type=text/javascript>
function hide(){
document.getElementById('text1').style.visibility='hidden';
}
function show(){
document.getElementById('text1').style.visibility='visible';
}
</script>

Web Pages are stateless. Microsoft brought in ViewState in ASP.NET 1.0 to accommodate for this. What I mean by stateless is there is no consistent connection between the client (users's computer) and the server (what hosts the web page the client is looking at). THe ViewState is a medium that was created to help bridge this buy retaining values on form controls during postbacks.

If you are using ASP.NET MVC, you will lose the data in your boxes. ASP.NET MVC does not use the ViewState (thankfully). This is why it's recommended that with ASP.NET MVC you use AJAX to communicate to your server. If you would like to understand more about this, check this out: asp.net c# MVC: How do I live without ViewState?

If you are using regular website/web application projects, your data will remain intact if you enable the viewstate (This is enabled by default).

To disable / enable viewstate see the following for ASPX headers:

<%@ Page Language="C#" EnableViewState="false" %>
<%@ Page Language="C#" EnableViewState="true" %>

Viewstate: http://msdn.microsoft.com/en-us/library/ms972976.aspx

Community
  • 1
  • 1
Ryan Ternier
  • 8,714
  • 4
  • 46
  • 69