开发者

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


Change onClick to OnClientClick


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜