473,469 Members | 1,568 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Fire Javascript method on BUTTON click??!?

OK, I've got a basic webform set up, with several buttons that I want to
trigger different things on when they're clicked. For example, when the
onClick event is triggered on one, I want a javascript method to fire and
open a new window, redirecting to either another page on my site or a page
off-site.

1) How do I do this? A traditional "onclick" event on the control line
doesn't work, and setting up the CommandName/CommandArgument properties
doesn't work either.
2) How can I do something WITHOUT a button performing a SUBMIT action??
I've tried wiring up the CommandName/OnClick/OnCommand events, and they
either don't call the method (if in the same script) or I get an error
telling me the "name isn't defined" (if the method IS defined in a
code-behind page)...

Thanks!
Jack
Nov 18 '05 #1
1 2095
Could you post the code that isn't working for you? Creating a button that
responds to an onclick to open a window but doesn't cause a postback is
pretty easy, so there must be something more to it that we need to see.

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Button1.Attributes.Add _
("onclick", _
"window.open('http://msdn." & _
"microsoft.com/asp.net/')" & _
";return false;")
End Sub

<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>
</form>

"Jack Black" <ja*************@hotmail.com> wrote in message
news:ev**************@TK2MSFTNGP12.phx.gbl...
OK, I've got a basic webform set up, with several buttons that I want to
trigger different things on when they're clicked. For example, when the
onClick event is triggered on one, I want a javascript method to fire and
open a new window, redirecting to either another page on my site or a page
off-site.

1) How do I do this? A traditional "onclick" event on the control line
doesn't work, and setting up the CommandName/CommandArgument properties
doesn't work either.
2) How can I do something WITHOUT a button performing a SUBMIT action??
I've tried wiring up the CommandName/OnClick/OnCommand events, and they
either don't call the method (if in the same script) or I get an error
telling me the "name isn't defined" (if the method IS defined in a
code-behind page)...

Thanks!
Jack


Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Carlo Marchesoni | last post by:
From an aspx page (A.aspx) I open another one (B.aspx - for table lookup). When the user selects an entry in B.aspx I would like to force a button's event in A.aspx to be fired. I guess the only...
4
by: Carlo Marchesoni | last post by:
I have a button that opens a new Window (some kind of search-window), which is fired using JavaScript (btnSearch.Attributes=".....";) Now I need to run some code behind code BEFORE this JavaScript...
8
by: tatemononai | last post by:
I had a beautiful script that was running, well, just beautifully. But then I decided to take a button that fired an event and place it inside a <asp:table. The event WILL NOT FIRE INSIDE THE...
6
by: Steve Booth | last post by:
I have a web form with a button and a placeholder, the button adds a user control to the placeholder (and removes any existing controls). The user control contains a single button. I have done all...
5
by: Verde | last post by:
This is admittedly an apparently odd request... but please indulge me if you don't mind: Suppose I have two <asp:Button.../> on a page (Button1 and Button2). User clicks Button1 and triggers a...
4
by: Ryan | last post by:
Hello, I have a standard HTML button on an aspx web form that I have set to runat server. The button is named reset1 and its tag is as follows: <INPUT id="btnReset1" style="WIDTH: 60px;...
4
by: Ty Salistean | last post by:
So, here is a wierd question that we have been discussing for a bit now. Does an event fire even though nothing is subscribed to listen to the event? For instance, does the Click event of a...
3
by: rfinch | last post by:
I'm trying to pass two values from client script (Javascript) to the code-behind for a page using three hidden fields - two to hold the values and a third to fire the ValueChanged event. I have...
19
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.