asp.net - How to share a variable value with a webmethod? -
i have code:
dim main_id int protected sub page_load(byval sender object, byval e system.eventargs) handles me.load main_id =1 end sub <webmethod()> _ public shared function bindpersonnel(byval product_id string) string dim project_id int16 project_id=main_id 'this doesn't work end function on page load, set value of variable main_id , need way somehow share main_id webmethod function, how can done? have not tried session variable , don't want use session variable. found link accessing common variable in webmethod , jquery can't figure out how going solve problem. read posts using hidden field, requires me go 2 trips. love avoid that.
webmethods independent of other variables on page. if want access main_id, declare private shared main_id integer, cause of users have access same id value, don't want.
perhaps easiest way store value in sessionstate, , enable sessionstate access in webmethod. on other hand, removes asynchronous-like functionality looking (it may not issue).
sessionstate give ability have per-session value (avoiding use of shared solution mentioned above).
protected sub page_load(byval sender object, byval e system.eventargs) handles me.load session("main_id") = 1 end sub <webmethod(enablesession:=true)> public shared function bindpersonnel(byval product_id string) string dim project_id integer = cint(httpcontext.current.session("main_id")) end function
Comments
Post a Comment