Surya sasidhar
Surya sasidhar

Reputation: 30303

javascript in button click event?

i place the onClick event in asp buttons. but it is showing error like

Too many characters in character literal

my code is

<asp:Button ID="Button1" runat="server" Text="Button" 
    onClick="alert('The button was clicked.');" />

actually my requirement is when i click on the button i want to display some message and when we press ok then it is redirect to another page is it possible

thank you

Upvotes: 0

Views: 782

Answers (2)

NibblyPig
NibblyPig

Reputation: 52932

Change onClick to OnClientClick

Upvotes: 2

Matthew Dresser
Matthew Dresser

Reputation: 11442

You need to use the OnClientClick method, OnClick is the server side event. e.g.

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return confirm('are you sure');" />

This code produces a message box which if cancelled, prevents the server-side event from being fired. If you click 'OK' to the message box the server event is fired as usual and you can then do your redirect as necessary.

Upvotes: 1

Related Questions