[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

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

Posted on 2011-02-22
8
Medium Priority
?
848 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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 2000 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

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

656 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