Saturday, 20 September 2014

Javascript Confirm Message On Submit Button Click In Asp.Net MVC Using C#.Net

9/20/2014 - By Pranav Singh 2

This article will show you how you can show confirmation message in your on click of submit button in asp.net mvc using c#.net and JavaScript.


So for this article first we will create a new asp.net mvc application and ad the below code in your controller.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MvcApplication2.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Index(string name)
        {
            ViewBag.Message = "You have pressed YES.";
            return View();
        }

    }
}

In above code http post method have been written, so this method will fire when click on ok button and message will pass in view bag to display.

Now create the view and add the below code

@{
    ViewBag.Title = "Javascript Confirm Message On Submit Button Click In Asp.Net MVC Using C#.Net";
}
<script>
    function Postsubmit() {
        var result = confirm("Are your sure. Do you want to submit?");
        if (result) {
            return true;
        } else {
            return false;
        }
    }
</script>
@using (Html.BeginForm("Index", "Home"))
{
    <div style="color:Red">@ViewBag.Message</div>
    <input type="submit" value="Submit" onclick="javascript:return Postsubmit();"/>
}

Now just check the above JavaScript code. In this code I have return yes if user pressed ok button. Now we have done run the application to check the output.




 DOWNLOAD

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

2 comments:

  1. An outstanding share! I've just forwarded this onto
    a friend who has been doing a little research on this.
    And he in fact bought me breakfast due to the fact
    that I found it for him... lol. So let me reword
    this.... Thanks for the meal!! But yeah, thanx for spending time
    to discuss this matter here on your web page.

    ReplyDelete

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top