Click here to Skip to main content
15,901,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a MVC 3 razor view application . I dragged and droped a submit button in to the layout.cshtml. now i need to add an event handler to it. i don't see any option in the property window like before i did in aspx. how do i do it..
Posted

Submit buttom is an HTML element. So, only javascript can be invoked with the submit button. Also, The Submit button with form automatically submits the page to server when clicked. You just have to specify action attribute for the form, no javascript code is needed here.

Yet, if you would like to add custom processing you can code either in pure javascript or jQuery.

ex:jquery event handler for submit button whose id=btnSubmit
C#
<script type="text/javascript">
$(document).ready(function () {
    $("#btnSubmit").click(function (e) {
        alert("submit");
    });
});
</script>
 
Share this answer
 
You can try onclick event of submit button to call some javascript function.
<input type="submit" id="btnSubmit" onclick="javascript:onSubmitButtonClick(); return false;" />

XML
<script type="text/javascript" language="javascript">
 function onSubmitButtonClick() {
   alert("submit button clicked");
 }
</script>
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900