asp:net button and javascript

A

Anton ml. Vahèiè

Hi,

Can anyone tell me how I convince my
<asp:Button id="Button1" onclick="stopClock()" style="Z-INDEX: 101; LEFT:
8px; POSITION: absolute; TOP: 136px" runat="server"
Text="Button"></asp:Button>
that will run javascript function - stopClock()

Regular html button does not seem to have a problem with that.

Anton, ml.
 
D

Dan

Change tag in your webform to:

<asp:Button id="Button1" style="Z-INDEX: 101; LEFT:
8px; POSITION: absolute; TOP: 136px" runat="server"
Text="Button"></asp:Button>

And then in your Page_Load, do:

Button1.Attributes.Add("onClick", stopClock()")
 
A

Anton ml. Vahèiè

Hi,

Smart. Thanks. Maybe one more question if you know perhaps. If my
JavaScript function stopClock() return some string (let's say "Today") and I
want that my Button1.Text is now changed to "Today". How do I do it?

Greetings,
Anton, ml.


----- Original Message -----
From: "Dan" <[email protected]>
Newsgroups: microsoft.public.dotnet.framework.aspnet
Sent: Thursday, February 12, 2004 3:42 PM
Subject: Re: asp:net button and javascript
 
J

Jeff Carver

You're trying to fire a client event from the server. This is what
you need to do:

1. Add this to Page_Load:

Button1.Attributes.Add ("onclick", "javascript:stopClock(); return
false;");

[Note that "return false" keeps the page from being posted; take that
out if you do want the page to be posted.]

2. Change the button declaration to this:

<asp:Button id="Button1" style="Z-INDEX: 101; LEFT: 8px; POSITION:
absolute; TOP: 136px" runat="server" Text="Button" />

[You might also want to set the CausesValidation property to false.]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top