Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
i have a gridview where each row contains a delete link that calls a javascript function which doesn't do what he suposed to do (to dispaly message that delete is not allowed if the number of row in database is less then 3, to ask a user if he wants to delete if the number is between 3 and 5, and to always allow him if the number is more than 5):
XML
<asp:LinkButton ID="lnkRemove" runat="server" CommandArgument='<%# Eval("CustomerID")%>'
                                    OnClientClick="return validateLink()" Text="Delete" OnClick="DeleteCustomer"></asp:LinkButton>

the following lines are the javascript function:
JavaScript
function validateLink() {
        PageMethods.getSqlCountAjax(onRequestComplete, onError); // call to yr AJAX function to get sql count
        
        function onRequestComplete(result) {
            var sqlCount = result;
            if (sqlCount > 5) {
                return true;
            } else if (sqlCount >= 3 || sqlCount <= 5) {
                if (confirm('yr confirmation mesaage here...') == 1) {
                    return true;
                }
            } else {
                alert('not allowed to navigate to this page');
                return false;
            }
            return false;
        }
    }

and the following lines represent my pagemethod defined in the codebehin class:and the following line represent my pagemethod defined in the codebehin class:
VB
<WebMethod()>
    <ScriptMethod()>
    Public Shared Function sqlCountAjax() As Integer
        Dim strConnString As String = ConfigurationManager.ConnectionStrings("conString").ConnectionString
        Dim strQuery As String = "select Count(*) As number from customers"
        Dim cmd As New SqlCommand(strQuery)
        cmd.CommandType = CommandType.Text
        Dim con As New SqlConnection(strConnString)
        con.Open()
        Dim records As Integer
        Return (records = CInt(cmd.ExecuteScalar))
        con.Close()
    End Function
Posted
Updated 10-Jun-12 8:14am
v2
Comments
Sandeep Mewara 10-Jun-12 13:30pm    
& What does it do that you say not supposed to do?
Vitaly Tomilov 10-Jun-12 17:14pm    
How is it that it doesn't work? What is going on exactly?

Sounds like something that needs to be handled on the client side, which means you can see what;s going on via the browser debugger, such as FireBug, for instance.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900