2

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.

tereško
  • 58,060
  • 25
  • 98
  • 150
haldar55
  • 59
  • 1
  • 1
  • 11

2 Answers2

2

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')"
                                });
wwcdwdcw
  • 186
  • 1
  • 8
1

Try something like below.

 <%= Html.TextBox("obpt9",ViewData.Eval("obpt9"), new { onclick = "alert('hi')" })%>

You can find more information from below link. Add OnClick Event to Html.RadioButton

Community
  • 1
  • 1
Jalpesh Vadgama
  • 13,653
  • 19
  • 72
  • 94