Remove text onclick/onfocus event of @Html.TextArea

haldar55 picture haldar55 · May 30, 2013 · Viewed 11.6k times · Source

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.

Answer

wwcdwdcw picture wwcdwdcw · May 30, 2013

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')"
                                });