Solved

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

Posted on 2011-02-22
8
839 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Please explain: Aspect Oriented Programming 2 53
Data Saving 5 30
Problem to page 4 23
C# TextBox 11 0
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 …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

706 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

22 Experts available now in Live!

Get 1:1 Help Now