how can I call a serversidefunction from javascript ?

Posted on 2009-04-30
Last Modified: 2012-05-06
this is my serverside code, how can I call this from  javascript and pass in a parameter.

protected void copyLine(string id)


       if(id == "1")



Open in new window

Question by:tech_question
    LVL 9

    Expert Comment

    I may be wrong, but I'm not 100% sure that this is actually possible, due to the JavaScript's limitations as a "language", Why not just do this all in ASP.NET?

    Again, I may be wrong; I'm not a JavaScript fanatic, or even a fan, for that matter.

    Author Comment

    how can I do that  - can you please post an example code? I am adding dynamically code to the onclick event of a linkbutton - but by default it is calculating it as a client side onclick - how can we make it to respect it as a serverside function ?
    LVL 14

    Accepted Solution


    Author Comment

    would this have any security impact in me doing this way ?
    LVL 14

    Expert Comment

    You are going to expose certain methods to be called from javascript using [WebMethod]. You can even control the unnecessary data by validating the input. These methods can't be called from other pages. Only the current page can invoke the server methods.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now