• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 147
  • Last Modified:

how can I call a serversidefunction from javascript ?

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")
        Response.Redirect("www.google.com");
    }

Open in new window

0
tech_question
Asked:
tech_question
  • 2
  • 2
1 Solution
 
tcullerCommented:
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.
0
 
tech_questionAuthor Commented:
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 ?
0
 
tech_questionAuthor Commented:
would this have any security impact in me doing this way ?
0
 
GiftsonDJohnCommented:
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.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now