0

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

1
  • ya it is working, but i want to redirect to another page i write code in button click event protected void Button1_Click(object sender, EventArgs e) Commented Jun 21, 2010 at 16:55

2 Answers 2

2

Change onClick to OnClientClick

Sign up to request clarification or add additional context in comments.

1 Comment

OnClientClick is the client side click event.
1

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.

2 Comments

ya it is working, but i want to redirect to another page i write code in button click event protected void Button1_Click(object sender, EventArgs e) { Response.Redirect("yahoo.com"); } but it is giving error
Hi, try changing it to the full address with the http bit i.e. Response.Redirect("http://www.yahoo.com");

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.