0

I want to use JavaScript code to call the code behind method. I tried something but it isn't working.

JavaScript code:

<script type="text/javascript">  
    function checkMe() {  
        alert("hello");  
        PageMethods.Counting;  
    }

    function onComplete(result, response, content) {  
        alert(result);  
    }  
</script>

Below is my dynamically created <a href=""> tag:

string.Format(@"<a href='{0}' onclick='checkMe();' runat='server'>{1}</a>", newlink.NavigateUrl, dt.Rows[contID]["FAQTITLE"].ToString()) ; 

When I click the <a href=""> tag how do I call the below method?

protected void Counting(object sender, EventArgs e)  
{  
    //my code is here   
}  
4
  • 1
    You can't mix server language code and client side javascript like that. They run at different times in different places Commented Jun 21, 2016 at 2:28
  • Are you using WebForms ? Then go for PageMethods Commented Jun 21, 2016 at 2:51
  • @Sami yes im using WebForms. Commented Jun 21, 2016 at 2:53
  • try using ajax to call code behind function. Commented Jun 21, 2016 at 4:55

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.