display label for 5 sec

Last post 01-23-2008 8:51 AM by NC01. 8 replies.

Sort Posts:

  • display label for 5 sec

    01-23-2008, 7:12 AM
    • Member
      189 point Member
    • syedwna
    • Member since 09-01-2006, 9:56 AM
    • Posts 514

    i want to display a lable when i submit a button for 5 sec

    how to do that in asp.net 2.0

    or

    javascript.

    Mark As Answer If my reply helped you.
  • Re: display label for 5 sec

    01-23-2008, 7:51 AM
    • Participant
      1,390 point Participant
    • apurva kaushal
    • Member since 05-05-2006, 12:34 PM
    • Hyderabad
    • Posts 302

     Javascript can be used for that purpose.

    This you can take as an example and modify according to your need.

    <script type="text/javascript">
    function remind(msg1) {
    var msg = "This is a reminder after " + msg1 +" Secs";
    alert(msg);
    }
    </script> 

    Apurva Kaushal
  • Re: display label for 5 sec

    01-23-2008, 7:51 AM

    You can add a div to your page something like this:

    <div id="labeltoshow" style="visibility:hidden"> (ANYTHING YOU WANT HERE) </div>

    And then the Onclick of your button should call a method like "ShowLabel();

    example <input type="button" ... onclick="ShowLabel(); return false;">  If you are using an ASP.NET button from the server side then you have to add OnClientClick and not OnClick.

    In your javascript function ShowLabel(), you show the div by getting a reference to it using something like

    document.getElementById('labeltoshow').style.visibility = 'visible'; // this will set it to visible

    and then you set a timer for 5 seconds using setTimeout javascript function.

    When the 5 seconds are done, it will call another javascript function that you have specified in your setTimeout call, there you submit your page.

    Hope this helps.

     

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    My Blog
    If you get the answer to your question, please mark it as the answer.
  • Re: display label for 5 sec

    01-23-2008, 7:51 AM
    • Star
      8,559 point Star
    • siva_sm
    • Member since 12-20-2007, 11:03 AM
    • Posts 1,256

    If you want the postback to happen after 5 secs, then call the function displayMsg() on submit button click: 

    // Global variable
    var l = document.all["<%= LabelControl.ClientID %>"];
    
    function displayMsg()
    {
      l.innerText = "Please wait...";
      setTimeout("doSubmit();", 5000);
    }
    
    function doSubmit()
    {
      l.innerText = "";
      

    <%= ClientScript.GetPostBackEventReference (new PostBackOptions (this)); %>

    }
     
    Mark replies as answers if they helped you solve the problem.
  • Re: display label for 5 sec

    01-23-2008, 7:52 AM

    hi ,

    <%@ Page Language="C#" Debug="true" %>
    <script runat="server">

        void Page_Load()
        {
           if (Page.IsPostBack)
             lblOut.Visible = !lblOut.Visible;
        }

    </script>
    <html>
    <head>
    </head>
    <body>
        <form runat="server">
            Click Submit several times 
            <asp:Button id="Button1" runat="server" Text="Submit"></asp:Button>
            <asp:Label id="lblOut" runat="server" text="See Me"></asp:Label>
        </form>
    </body>
    </html>

    Hope works for u

    Regards,
    Saritha
  • Re: display label for 5 sec

    01-23-2008, 7:56 AM
    • Contributor
      2,103 point Contributor
    • realfantasy
    • Member since 12-02-2007, 9:06 AM
    • Lahore, Pakistan
    • Posts 309
    sample code for you 
    <asp:button ID="btnSubmit" runat="server" OnClientClick="SetTimeOut();" />
    <asp:Label ID="lblStatus" runat="server" Text="Updated!"></asp:Label>
    <script type="text/javascript">
    function SetTimeOut()
    {
    setTimeout("HideLabel()", 5000);
    }
    function HideLabel()
    {
    document.getElementById('lblStatus').style.display = 'none';
    }
    </script>

     

    Filed under:
  • Re: display label for 5 sec

    01-23-2008, 8:04 AM

    Hi,
    Try this

    Register following script to RegisterStartupScript After finishing post back functionality in button click event.

    like this

    this.RegisterStartupScript("setHide", "setTimeout(\"function(){document.getElementById('"+ lable.ClientID+"').visibility='hidden';};\", 5000);");


    Nikhil Agrawal
    Think before you Think
  • Re: display label for 5 sec

    01-23-2008, 8:21 AM
    • Member
      2 point Member
    • gayatrys
    • Member since 11-16-2006, 7:45 AM
    • Posts 2

    Hi,

    You can do it using Java script.  Following are the script and code.

    <script language="JavaScript" type="text/javascript">

     

    function closePrnWindow()

    {

    if (window.document.readyState == "complete")

    {

    document.getElementById(
    'Label1').style.display="none";

    }

    else

    {

    setTimeout(
    "closePrnWindow()",5000)};

    }

    </script>

     

      In Vb page load event.

    Dim _script As String = "<Script>closePrnWindow();</Script>"

    Page.ClientScript.RegisterStartupScript(GetType(Page), "DoScript1", _script)

     Try this,

     

    Regards,

    Gayatry.S

     

  • Re: display label for 5 sec

    01-23-2008, 8:51 AM
    Answer
    • All-Star
      74,877 point All-Star
    • NC01
    • Member since 08-26-2005, 7:33 PM
    • Posts 13,917
    • TrustedFriends-MVPs

    This has nothing to do with ASP.NET 2.0 since you need client-side script, which will work with any .NET version, to do that. You would have to hijack the entire PostBack process to do it. You would need to use HTML buttons instead of ASP.NET buttons.

    Here is an example:

    aspx file:

    <form id="Form1" method="post" runat="server">
     <input type="button" id="submitButton" value="Submit" onclick="JavaScript: startTimedPostBack();">
     <span id="timedLabel" style="display:none">This text is displayed within the timed PostBack!</span>
    </form>

    <script type="text/JavaScript">
    <!--
    var timerId = null;

    function startTimedPostBack()
    {
     document.getElementById('timedLabel').style.display = 'block';
     timerId = window.setTimeout('doTimedPostBack()', 5000); // 1000 = 1 second
    }

    function doTimedPostBack()
    {
     document.getElementById('timedLabel').style.display = 'none';
     window.clearTimeout(timerId);
     __doPostBack('submitButton', '');
    }
    // -->
    </script>

    aspx.cs file:

    private void Page_Load(object sender, System.EventArgs e)
    {
     // Insure that the __doPostBack() JavaScript method is created...
     this.GetPostBackEventReference(this, string.Empty);

     if ( this.IsPostBack )
     {
      string eventTarget = (this.Request["__EVENTTARGET"] == null) ? string.Empty : this.Request["__EVENTTARGET"];

      if ( eventTarget == "submitButton" )
      {
       submitButton_Click();
      }
     }
    }

    private void submitButton_Click()
    {
     this.Response.Write("submitButton_Click fired. <br>");
    }

    NC...

Page 1 of 1 (9 items)