asp.net-mvcasp.net-mvc-3onclickhtml.textbox

Remove text onclick/onfocus event of @Html.TextArea


I am working on an MVC 3 project. In my view I have textboxes and Text area which I am calling using @Html.TextBox/TextArea.

Can anyone please tell me, how can I define the onclick or onfocus even of these controls? I am unable to find a syntax for this.


Solution

  • TextBox

    @Html.TextBox("ControlName",
                    "Some Value",
                      new { onclick = "alert('Razor Engine')" });
    @Html.TextBoxFor(m => m.Value, new
                                    {
                                        onclick = "alert('Razor Engine')",
                                        @Value = "Some Value"
                                    });
    

    TextArea

    @Html.TextArea("ControlName",
                    "Some Value",
                      new { onclick = "alert('Razor Engine')" });
    @Html.TextAreaFor(m => m.Value, new
                                    {
                                        onclick = "alert('Razor Engine')"
                                    });