c# - Call CodeBehind Method from JavaScript with parameter -


i'm trying call code behind method javascript code. works fine, not sure how can pass javascript parameter method. if put value between parenthesis, related codebehind context rather script context. solution pass parameter?

javascript:

var arg = this.id <% setselection(arg); %>    

c#:

[webmethod] public void setselection(string productid) {    session["selection"] = productid } 

i error of course: cs0103: name 'arg' not exist in current context

your setselection(arg) call not calling code behind javascript. getting called on server side, before html response output browser, way before javascript executes. arg treated c# variable.

if want make call javascript, need use ajax. see this example.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -