Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Dec 2009
    Posts
    42
    Thanks
    13
    Thanked 0 Times in 0 Posts

    onclick event - js and ASP.NET

    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

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,020
    Thanks
    75
    Thanked 4,323 Times in 4,289 Posts
    Easy answer is to *NOT* use an <asp:button> for Cancel.

    Just use ordinary HTML button:

    Code:
    <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.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •