Solved

Need to have a delay in my code before resetting textbox's text value

Posted on 2011-02-22
8
843 Views
Last Modified: 2012-06-21
Hello Experts,

I have an asp:Literal tool setup on my form to hold system messages. On my form I am inserting data to my database. When the submit button is pressed the System Message returns a message "Data Saved!". Then all the fields are set to their default value. I need to have a delay of 5 seconds and then have the controls text value change to "" the default.

When I use Thread.Sleep(5000); All of the processes are held for 5 seconds then process. I need them to run up to that point then delay 5 seconds then reset the system message text.

Jeff
0
Comment
Question by:woodje
[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
  • 4
  • 4
8 Comments
 
LVL 22

Expert Comment

by:pivar
ID: 34955296
Hi,

You could use the Timer class. Check this for an example
http://www.java2s.com/Code/CSharp/GUI-Windows-Form/GUIandtimer.htm

/peter
0
 
LVL 22

Expert Comment

by:pivar
ID: 34955545
Sorry, I neglected to notice that you want this for asp.

But there is an equivalent timer funtion in javascript you could use.
Try
setTimeout('function to clear your label', 5000)
0
 

Author Comment

by:woodje
ID: 34955836
pivar,

Thanks for the response I am new to Javascript programming can you show me an example of what you are discussing? The element I am trying to set the text to " " has an ID="SystemMessages".

Jeff
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 22

Expert Comment

by:pivar
ID: 34956003
Please try this:

   protected void Page_Load(object sender, EventArgs e)
    {
        this.btnSubmit.Attributes.Add("onClick", "setTimeout(\"document.getElementById('" + yourliteral.ClientID + "').value='';\",5000)");
    }
0
 

Author Comment

by:woodje
ID: 34998489
pivar,

Thanks for the response. I guess I am having problems understanding how this is operating. I have a submit button. That updates my database and sets the literal control text to "Your Record has been Saved!!". And then resets the page back to baseline. What I need is for the literal text to be set back to baseline after a 5 second delay. With my setting back to baseline right now everything happens so fast the Save text is not appearing. I need my user to see it then have it reset.

Jeff
0
 
LVL 22

Accepted Solution

by:
pivar earned 500 total points
ID: 35001701
Try this instead, and change your asp:Literal to a asp:Label


            protected void btnSubmit_Click(object sender, EventArgs e) {
                  yourLabel.Text = "Your Record has been Saved!!";

                  System.Text.StringBuilder sb = new System.Text.StringBuilder();
                  sb.Append("<script language='javascript'>");
                  sb.Append("setTimeout(\"document.getElementById('" + yourLabel.ClientID + "').firstChild.data = ''\", 5000);");
                  sb.Append("</script>");

                  if (!ClientScript.IsStartupScriptRegistered("ClearLabelScript")) {
                        ClientScript.RegisterStartupScript(this.GetType(), "ClearLabelScript", sb.ToString());
                  }
            }
      }
0
 

Author Comment

by:woodje
ID: 35009616
Ok I will give that a try this evening and will post back.
0
 

Author Closing Comment

by:woodje
ID: 35193400
Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

Suggested Solutions

A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

733 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