Category Archives: Timer

[RESOLVED] count down timer in asp.net

hi,,  i have one text box  and one button,

i have some question,,plzzz give me answers

when i enter 60 in text box,and press buttton,,it will save 60  as a seconds,and this 60 seconds should save in database (( i m using SQL SERVER 2008),

when user  view quiz page,this 60 second starts count down to zero ..,

and when second become 0 ,alert display on page...with some message......

and i want this all work in asp .net (visual C#)..plzz give me some ideas...or code...

...

@above ..its not a solution to help....plzz give me some good reference,afterall its a asp.net forum...

if you want something to be done in the client's browser when the timer reaches zero, I think you would do that with javascript(that is clientside).

you can take a look at the link below to see how it works:

http://www.w3schools.com/js/js_timing.asp

[RESOLVED] How can I use the timer event to let an en event such as the window.onresize only run for 12 a second and then stop

My Javascript swaps out links in the head tag that control such things as which direction a menu pops out depending on where it is on the screen.  Unfortunately, because it changes the position of panels when it changes the links, it puts window.onresize into an endless loop.

I would like to just set the function to run for 1 millisecon everytime it runs and then top. 

How can I do that?

Ehm considering you hav no code here or anything but if you want to use the timer control you can look here

http://msdn.microsoft.com/en-us/library/bb386404.aspx

but I dont know if that answers want you want...if you post you code it might be easier to help you :)

[RESOLVED] Loading please wait in VB.NET while gridview loads data

Hi,

I am trying to display the loading please message or a spinning image while a page loads data in a gridview. Users click on a link from one page and get redirected to another page via the response.redirect method. The new page loads some data in a gridview based upon some variables passed. Some times it could take up to 20+ seconds for the gridview to load. I have displayed loading please wait message previously using the jQuery, Post and ajax methods etc. In this case it's just straight VB.NET code that makes a sql connection to the server, executes a stored procedure and binds the returned data to the gridview. I would like the message or image to start showing once they click on the link to get redirected to the new page and continue to display till the gridview data has been loaded. Here is an example of the code:

Try
Dim cmd As SqlCommand = New SqlCommand("CustOrderHist", New SqlConnection("Server=localhost;Database=Northwind;Trusted_Connection=True;"))
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.Parameters.AddWithValue("CustomerID", txtCustID.Text)
cmd.Connection.Open()
gvwExample.DataSource = cmd.ExecuteReader()
gvwExample.DataBind()
cmd.Connection.Close()
cmd.Connection.Dispose()
Catch ex As Exception
lblStatus.Text = ex.Message
End Try



Thanks

To avoid the loading time. What you can do is lazy load the gridview after the page is loaded using Updatepanel and Timer

This way your page will be loaded while the gridview will be populated later.

http://www.aspsnippets.com/Articles/Delay-Load-Lazy-Load-UpdatePanel-using-Timer-Control-in-ASP.Net.aspx 

Thank you, this trick seemed to work great for me.

[RESOLVED] display real time data in label using MS acccess database

Hi,

 

I need to display the real time data in the label.

Explain In detail: 

The camera is counting the people and store the counted value in database every minute.

so i need to pick the data and display it same on the screen. There are lot of cameras counting. So i need to take camera number and display respective count.

 

Camera NUmber Counted Value
1 Label1(Display realtime data here)
2 Label2

Can anybody advice me how and which way i can achieve this

Thanks in advance

If you want to do it in WebApp. Do it with AJAX controls. Add a ScriptManager control on top, add update panel and labels in it to update from database. Add a AJAX timer control for continuous update at specified interval.

Hi,

Thanks for your reply

I did the same its shows an error : the name 'label1' doesnt exists in current context

I explain my code here:

<div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> <asp:ScriptManager ID="ScriptManager1" runat="server"></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        </asp:ScriptManager> </div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode=Conditionals></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        <ContentTemplate></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            <asp:Timer ID="Timer1" runat="server" Interval="1000"></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            </asp:Timer></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        </ContentTemplate></div> <div style="position: absolute; left: -10000px; top: 26px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste">        </asp:UpdatePanel></div>

 <asp:ScriptManager ID="ScriptManager1" runat="server">

        </asp:ScriptManager> 

        <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode=Conditionals>

        <ContentTemplate>

            <asp:Timer ID="Timer1" runat="server" Interval="1000" onTick="Timer_Click">

            </asp:Timer>

            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>

        </ContentTemplate>

        </asp:UpdatePanel>


I check all way but still its through the same error. I'm using multiple UPDATEPANEL.

I'm using  15 updatepanel along with the timer to refresh and label to display data. But at .cs file i have used 

public void Timer_Click(object sender, EventArgs e)

{

  Dbcommection_Method();

Label1.Text = data ;

}


HERE it throughs "Label1" doesnt contain in current context


Thanks a lot

I think this is a Designer issue....delete the label control and re-add to the page....if still problem persists, then try by creating a new page and add controls one by one....

Thanks.

[RESOLVED] How to activate javascript function from Page_Load and updatepanel

Hi..

In the first Page_Load, I am activating a javascript function to make an ImageButton change between 2 images with an interval.

This works fine.

 

Now when pressing this imagebutton, the Page_Load event will fire the second time and all this is happening in an updatepanel which means a partial postback.

 

The question is how to execute the javascript function stopbk() in the Page_Load event in this scenario as I cant just put it in the "Onload". How can I make that work?

Code is below:

protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["SecondLoad"] != null)
        {
            //How to activate stopbk() ?
            Label1.Text = "Second Load";
        }


        if (Session["SecondLoad"] == null)
        {
            Label1.Text = "First Load";
            Session["SecondLoad"] = "dummy";
            body1.Attributes.Add("Onload", "startbk()");
        }
    }
    protected void ImageButton6_Click(object sender, ImageClickEventArgs e)
    {
        //
    }






<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>




<asp:UpdatePanel ID="UpdatePanel4" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<script type="text/javascript">
    var TimerProps = {
        refTimer: null,
        index: 0
    }
    function startTimer() {
        if (TimerProps.index > 1) {
            TimerProps.index = 0;
            document.getElementById('<%= ImageButton6.ClientID %>').src = "http://www.abc.com/images/inboxKuvert.jpg";
            TimerProps.index += 1;
        }
        else {
            document.getElementById('<%= ImageButton6.ClientID %>').src = "http://www.abc.com/images/Transparent.gif";
            TimerProps.index += 1;
        }
    }
    function startbk() {
        TimerProps.refTimer = setInterval("startTimer()", 550)
    }


    function stopbk() {
        clearInterval(TimerProps.refTimer)
    }
</script>


<asp:ImageButton ID="ImageButton6" runat="server" Height="12px" Width="16px"
 ImageUrl="http://www.abc.com/images/inboxKuvert.jpg" onclick="ImageButton6_Click" />


    <br />
    <asp:Label ID="Label1" runat="server" Text="-"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>


 

ASPusers

The question is how to execute the javascript function stopbk() in the Page_Load event in this scenari

ScriptManager.RegisterStartupScript()....

http://msdn.microsoft.com/en-us/library/system.web.ui.scriptmanager.registerstartupscript.aspx

Thanks.

Thank you,

I have tried to understand the example but are not 100% sure of how the parameters should be set.

My attempt is as below but are not sure if I have done it correctly, I think I miss something?

Example:

RegisterStartupScript( Control control, Type type, string key, string script, bool addScriptTags );

 

My attempt:
RegisterStartupScript(ImageButton6, GetType(), "???", "stopbk()", true); 

It seems to work with the example below:

Thank you!

 

 

protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["SecondLoad"] != null)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "stopbk", "stopbk();", true);
            Label1.Text = "Second Load";
        }


        if (Session["SecondLoad"] == null)
        {
            Label1.Text = "First Load";
            Session["SecondLoad"] = "dummy";
            ScriptManager.RegisterStartupScript(this, this.GetType(), "startbk", "startbk();", true);
        }
    }
    protected void ImageButton6_Click(object sender, ImageClickEventArgs e)
    {
        //
    }




<script type="text/javascript">
    var TimerProps = {
        refTimer: null,
        index: 0
    }


    function startTimer() {
        if (TimerProps.index > 1) {
            TimerProps.index = 0;
            document.getElementById('<%= ImageButton6.ClientID %>').src = "http://www.abc.com/images/inboxKuvert.jpg";
            TimerProps.index += 1;
        }
        else {
            document.getElementById('<%= ImageButton6.ClientID %>').src = "http://www.abc.com/images/Transparent.gif";
            TimerProps.index += 1;
        }
    }
    function startbk() {
        TimerProps.refTimer = setInterval("startTimer()", 550)
    }
    function stopbk() {
        clearInterval(TimerProps.refTimer)
    }
    </script>