c# - How do I call a static method on my ASP.Net page, from Javascript? -


sorry if simple answer, can't seem find (on or google.)

i have aspx page, gridview , each record has button.

what need execute bit of javascript on each record requests bit of data underlying page class. method on class static, i'm not interested in instance.

also, want call method without doing postback. can done and, if so, how do this?

note

i know wants code but, essentially, i'm looking snippet can put within onclientclick event. this:

<asp:button id="mybutton"      runat="server"      ...      onclientclick='pageclass.usermustconfirm()?confirm("are sure want continue?") : true ' /> 

like others in comments have said, you're going need use ajax or pagemethods...but wanted clear few misconceptions may have how works in first place.

there clear separation code runs in client vs code runs in server -- no way call server code directly client code -- how there be? instead, need make request server code "lives", response, , meaningful in client -- pagemethods does: opens method webmethod , lets client code seamlessly.

but shouldn't that.

instead of relying on ancient framework (webforms), using jquery's $.ajax(...) , promise objects in more explicit, framework-agnostic way.

short answer: cannot directly call c# javascript runs (in browser @ least).

long answer: can use ajax send server parameters call c# code , returned result.

hope helps!


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -