Clearing Forms in C#

Discussion in 'ASP.NET / ASP.NET Core' started by helric, Jul 31, 2004.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Is there a way to reset all web UI controls through C#? I have a code-behind C# app and I just want a way to clear all the text boxes on the page. Problem is that the page is dynamic so I won't know how many text boxes there are to clear. I was going to build my own collection and walk through that but I got to thinking that there's probably a very simple page.reset or something that I could use.

    I basically just want to re-initialize the aspx page and send it back to it's original form.

    Rich.
     
  2. Bruce

    Bruce DiscountASP.NET Staff

    rich,

    i do not think there's method to reset all the controls in a page (I could be wrong though).



    quote:Originally posted by helric

    Is there a way to reset all web UI controls through C#? I have a code-behind C# app and I just want a way to clear all the text boxes on the page. Problem is that the page is dynamic so I won't know how many text boxes there are to clear. I was going to build my own collection and walk through that but I got to thinking that there's probably a very simple page.reset or something that I could use.

    I basically just want to re-initialize the aspx page and send it back to it's original form.

    Rich.
    </blockquote id="quote"></font id="quote">
     
  3. So I was able to acheive what I wanted in this case by just redirecting to the same page. Doing so seems to dump all the form info.

    <center>Response.Redirect(this.Request.Url.AbsoluteUri);</font id="Courier New"></center>

    Kind of a cheesy way to do it but it works.

    Rich.
     
  4. Bruce

    Bruce DiscountASP.NET Staff

    that will definitely do it but you'll lose all other page view stuff

    \quote:Originally posted by helric

    So I was able to acheive what I wanted in this case by just redirecting to the same page. Doing so seems to dump all the form info.

    <center>Response.Redirect(this.Request.Url.AbsoluteUri);</font id="Courier New"></center>

    Kind of a cheesy way to do it but it works.

    Rich.
    </blockquote id="quote"></font id="quote">
     
  5. The Page object gives you access to the Controls collection. Once you have a reference, you can loop through all controls on the page. It doesn't matter that the controls where placed dynamically.

    Hope this helps
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page