Timer in asp.net

  • Thread starter Thread starter Mr Red
  • Start date Start date
M

Mr Red

Hi all,

I have one label and one button. When I click the button
the label shows "Hello world". What I want to do is after
5 second the hello world is clear. How to do it with
asp.net. Im using vb.net as the languages.

Thanks
 
Hello there,

I try to use the code, I already add the javascript code
inside my asp.net but I have a problem when I call the
function. This is my code

<asp:Button id="btnUpdate" runat="server" Text="Update"
OnClick="startClock()"></asp:Button>

the error message pointer at OnClick="startClock()":
'startClock' is not a member of 'ASP.USER_aspx'.

any idea?

Thanks
 
the error message pointer at OnClick="startClock()":
'startClock' is not a member of 'ASP.USER_aspx'.

That's correct. You've defined a web control and told it to run a procedure
called startClock() when it's clicked. Because of the runat=server, the page
will post back and try to run a server-side procedure called startClock().
You need to:

1) Create a client-side Javascript function called startClock()

2) Change the web control button to a regular HTML control: <input
type=button id=btnUpdate value=Update onClick="startClock();"> control.
Rendering it as a web control won't give you any advantage in this case
because you don't need it to interact with the server when it's clicked
 
Is there any possibility that Im using button from
asp.net rather then from the html? or maybe I can call
the function from code behine?

Thanks
 
On the web, the page just lives the time of the request. It will be much
more easy to have a client side timer. Plus if you want to hide the button
server side you'll have also an extra request to the server.

ASP.NET does quite a good job to mimic usual event based programming but IMO
it's worth to know what goes under the hood...

Patrice
 
Yes, you can keep asp.net button. You just need to add client side onclick
attribute like this (C# syntax):

btnUpdate.Attributes["onclick"']="startClock()";

Eliyahu
 
Back
Top