Solved

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

Posted on 2011-02-22
8
840 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
  • 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

911 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now