CALLING JAVASCRIPT FUNCTION IN ASP.NET MVC

Carl Pieterson

Total Post:14

Points:98
Posted by  Carl Pieterson
 11302  View(s)
Ratings:
Rate this:

hi,

I want to call java script function when I make my control by inline code in mvc. Pls. help me.

Thanks.

  1. Chris Anderson

    Post:65

    Points:455
    Re: Calling JavaScript function in asp.net MVC

    hello,

    First create a java script function-->

            <script type="text/javascript">
                function selectedIndexChanged() {
                           alert("Hello");   
                }
                function ontextChanged(){
                            alert("Hello")
               }
            </script>

    Then call that function by using control which is made by inline code, as below:

    <%:Html.DropDownListFor(x => x.SelectedProduct, new SelectList(Model.Products, "Value", "Text"), "Please Select a product", new { id = "dropDown1", onchange="selectedIndexChanged()" })%>

    <%:Html.TextBoxFor(x => x.Name,new {id="txtName",onkeypress="ontextChanged()" })%>

    Try it. This will help you.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!