my code is executed without clicking on it (which results in nullpointers because its called too early), this is my code :
Site.Master
<input type="submit" onclick="<%MvcApplication2.MvcApplication.hc.setLang("nl");%>" value="submit">
i have 3 questions about this situation
- is the code between <%..%> executed at compile time?
- is this even gonna work (putting <%%> in onclick)?
- is there a better way of calling methods from my C# class?
thx in advance
Thats correct.
Code breaks get rendered server side before being passed to the client.
If you wish to only run this
onclickof theinputyou could use AJAX to make a server side call to that method.