View Full Version : onclick event - js and ASP.NET

12-07-2009, 08:59 PM

New to javascript. Doing web page with ASP/VB.NET. Have text boxes for UI on page. Two command buttons - Submit (for db update) and Cancel. I need the Cancel button to prompt the user to verify cancellation. Need OK/Cancel buttons on alert. If user selects Cancel-no action. If user selects OK then I want the text boxes cleared of user text input and focus returned to first text box. I think this may be the code but do not know how to apply it.

function Clear()
var res=window.confirm("Please confirm cancellation-text boxes will be cleared");

Is this code valid or invalid for the events I need? How do I set it to fire when user clicks the ASP Cancel button?



Old Pedant
12-07-2009, 09:25 PM
Easy answer is to *NOT* use an <asp:button> for Cancel.

Just use ordinary HTML button:

<input type="button" value="Cancel" onClick="Clear( )" />

And then, yes, I think your JS code for Clear() looks right.

But are you sure those are the right ID's for those text boxes??? I think ASP.NET munges the ID you give in the ASP.NET form to give you a different client-side ID.

To find out, bring up the page in your browser and then do a VIEW==>>SOURCE to look at the HTML ASP.NET is generating. Verify the ID's of those fields.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum