...

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



JohnShell
12-07-2009, 07:59 PM
Hi,

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");
if(res==true)
{
document.getElementById("StrtDte").value="";
document.getElementById("EndDte").value="";
document.getElementById("txtProjRegHrsAl").value="";
document.getElementById("txtProjOTHrsAl").value="";
document.getElementById("ddlRAS").focus();
}
}

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?

Thanks,

John

Old Pedant
12-07-2009, 08: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