Prev: Pass changing values to parameter to Crystal Report scroll thru re
Next: Need Help Using A Custom Session Manager
From: Mark Rae [MVP] on 1 Apr 2010 10:49 "JohnE" <JohnE(a)discussions.microsoft.com> wrote in message news:EA0B98B1-3475-4965-A29A-90EC58612D47(a)microsoft.com... > Thanks to everyone for their feedback. Hopefully to aid your understanding, <asp:Button /> webcontrols have an OnClick method and, since v2, an OnClientClick method. There's no need to use Attributes.Add("onclick", .......) any more, unless you're still using v1.x. OnClick runs on the server and OnClientClick (as its name suggests) runs on the client. <asp:Button /> webcontrols can have one or both of these events at the same time. In fact, it's usual to have both because the OnClientClick event runs first and, if it returns false, then the server-side OnClick event doesn't fire. This is immensely useful e.g. in getting users to confirm server-side actions, e.g. <asp:Button ID="MyButton" runat="server" Text="Delete" OnClick="MyButton_Click" OnClientClick="return confirm('Are you sure?');" /> Clicking the above button will cause the JavaScript prompt to fire and, if the user responds "No", the server-side event won't even be called... I use this all the time, especially for client-side validation... -- Mark Rae ASP.NET MVP http://www.markrae.net
From: JohnE on 1 Apr 2010 22:43
"JohnE" wrote: > Hello. I have an asp:Button that in the click event I would like to have it > run a javascript function (function ProteusListPrint()). I currently have > the following in the click event; > > btnProteusListPrint.Attributes.Add("onclick", "ProteusListPrint()"); > > This is not working. Am I missing something or is this not the correct way > to reference it in the click event of the button (C#)? > > Thanks... John > > I would like to thank everyone that responded. It is the info gathered (right or wrong) that has a tendency to be remembered. I learned several things from this post that no doubt will be used again. Thanks. |