[Solved] How to call a method from an onclick button? – visual studio


I have this code which I need it to be read only once at the start of the program

The example gives field initializers on a controller. A controller instance is not synonymous with a “program”; a controller instance more commonly maps to a single request (although in the case of partials, it can actually be just a fragment of a request).

If you want to do something once and once only, a static field initializer may be useful; however, it is unclear what you would want to do in your scenario, as with anything static, the scores would be shared between all users – not usually what is wanted. Also: unless you understand concurrency in the context of your chosen framework (which from the question: you don’t), static fields should usually be readonly and immutable.

A more appropriate solution in your case is probably per-client state; probably “session-state”.

2

solved How to call a method from an onclick button? – visual studio