2

I have a asp link

<asp:LinkButton ID="next" CssClass="Button Large" runat="server" OnClick="Next_Click" OnClientClick="showBillingRequiredState(this)">Next</asp:LinkButton>

When its clicked I want to cancel the page from continue , I want it to just cancel processing if my javascript return false. Right now I am showing an error but then the error dissapears and it doesnt stick.. something is causing it refresh and I lose my error. Here is the javascript, as I mentioned it passes fine through all my conditions and it shows the div, but then after a second it dissapears.

 function showrequired(evt) {
        var code = document.getElementById('<%=codelist.ClientID%>').options[document.getElementById('<%=codelist.ClientID%>').selectedIndex].value;
        var currentValue= document.getElementById('<%=statevalue.ClientID%>').value;
        var eDiv = document.getElementById('reqDiv');

        if (code == "US" && currentValue.trim() == '') {
            eDiv.style.display = 'block';
            return false;
        }
        else {
            eDiv.style.display = 'none';
        }

     }
1
  • You should not set the display property to "block", but to "" (empty string). The default display for buttons is "inline–block", setting it to empty string allows it to return to the default or whatever is set by CSS. Commented Dec 18, 2012 at 2:56

2 Answers 2

2

Try:

 OnClientClick=" return showBillingRequiredState(this)"
Sign up to request clarification or add additional context in comments.

Comments

0

jquery event default works really well in such situation

<script>
$("#<%= next.ClientID %>").click(function(event) {

 var countryCode = document.getElementById('<%=lstBillingCountryCode.ClientID%>').options[document.getElementById('<%=lstBillingCountryCode.ClientID%>').selectedIndex].value;
        var currentStateValue = document.getElementById('<%=txtBillingState.ClientID%>').value;
        var errorDiv = document.getElementById('reqBillingState');

        if (countryCode == "US" && currentStateValue.trim() == '') {
            errorDiv.style.display = 'block';
           event.preventDefault();
           //while stepping through this with firebug, it gets here fine but then it just gets ignored
        }
        else {
            errorDiv.style.display = 'none';
        }



});
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.