I am new to RAZOR and now I need to trigger an event when users clicked a button, so I can run a lines of code to handle the event.
I don’t want to use it with MVC, and I don’t want to use JavaScript because I only want to explore the power of RAZOR.
I was surprised when someone told me that the way of event-drive methods has been discarded in the RAZOR, that’s alright. But my question is
what is the way to handle/response a click event (in the RAZOR syntax) which is the simplest thing in the ASP.NET Web Form applications?
The reason why I’m asking this question is I found that even the easiest thing like I want to write a fragment of code to response users’ input hard to be done(or should I say there is no way to do it) in the RAZOR.
You can take a look the discussion in my previous post.
ASP.NET RAZOR cannot capture the event
I hope there are some guys who can guide me through the first and tough step.
Thanks.
Update:
It seems that there is really no way to handle the user events in any way without the help of MVC framework. Thank you guys for your answers. I’d like to leave this post a few days longer and hopefully I could see someone post something interesting.
Thank you again.
There is no such thing like a click event in Razor.
Event handling is a concept that was used in WinForms. The event model in classic ASP.NET WebForms was an effort to translate the Windows programming model to the web, which, frankly, didn’t work very well. A stateful event model and web programming pretty much contradict each other.
If you want to work with events then use classic ASP.NET WebForms. If you want to embrace the web and not work against it, learn ASP.NET MVC, Razor, etc.
Don’t try to fit a stateful legacy paradigm on a stateless infrastructure. This is what Microsoft did with WebForms and that is where it should stay.