Solved

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

Posted on 2011-02-22
8
845 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
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

707 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