Click here to Skip to main content
15,914,780 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi, i have a datagrid in my table and in each row of the datagrid i have an hyperlink that allows a user to either naviguate to a certain page or stay in the current page. in other hand, my hyperlink do a "Count" in sql request, and if the number returned of the sql request is superior to 15, it navigates you to a second page, else if it's between 10 to 15, it shows you a confirm message (if you click "ok" then you will navigate to the other page, else you will stay in the current page), else it shows you a message that shows you that you can't navigate to the other page.
Posted

the solution1 is good and here I explain to you how to add to your code behind a page method and use it in javascript:
here is your code behind:
C#
[WebMethod]
        [ScriptMethod]
        public static int getSqlCountAjax()
        {
        //write your code here for this method
        }

then use script manager and enable pagemethod property:
C#
function validateLink() {
    PageMethods.getSqlCountAjax(onRequestComplete, onError); // call to yr AJAX function to get sql count

    function onRequestComplete(result) {
        var sqlCount = result;
        if (sqlCount > 15) {
            return true;
        } else if (sqlCount >= 10 || sqlCount <= 15) {
            if (confirm('yr confirmation mesaage here...') == 1) {
                return true;
            }
        } else {
            alert('not allowed to navigate to this page');
            return false;
        }
        return false;
    }
}
 
Share this answer
 
v3
Comments
elidrissi.amine1 7-Jun-12 13:49pm    
i need some explainations, do i have to put the "validateLink()" under
<script type="text/javascript" language="javascript" runat="server"></script>
which will be included under <asp:Content ID="Content3" ContentPlaceHolderID="content" runat="server"> which contain my hyperlink.
i expect that in the "onClientClick" of my hyperlink i have to call the "validateLink()" method. by doing what i describe before first it seems that "PageMethods" which is called in the "validateLink()" isn't known even if i put <asp:ScriptManager ID="ScriptManager1" runat="server"
EnablePageMethods="True">
click here

Script

function validateLink() {
var sqlCount = getSqlCountAjax(); // call to yr AJAX function to get sql count
if(sqlCount >15) {
return true;
}
else if(sqlCount >= 10 || sqlCount <=15) {
if( confirm('yr confirmation mesaage here...') == 1) {
return true;
}
}
else {
alert('not allowed to navigate to this page');
return false;
}
}

Regards
Niral Soni
 
Share this answer
 

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