Tuesday, 30 September 2014

Popup Window Open Without Page Refresh in Asp.net MVC Using javaScript

9/30/2014 - By Pranav Singh 0

This article will show you how you can open popup window without page refresh on click of submit button in asp.net mvc using JavaScript.


So for this article we will create a new mvc application and add a controller file in it. In this controller file add the below code.

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

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

        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Index(int id = 0)
        {
            return View();
        }
        public ActionResult WelcomePage()
        {          
            ViewBag.PopupValue = "THIS IS POPUP WINDOW";
            return View();
        }
    }
}

In above code I have index and welcome action result. In this article I will open the welcome window as popup window using javascript.

Now we will create view and add the below code in it.

INDEX
@{
    ViewBag.Title = "Popup window open without page refresh in asp.net mvc using javascript";
}
<script language="javascript">
    function openPopupWindow() {
        window.open('/Home/WelcomePage/', 'Page', "width=300, height=200");
        return false;
    }
</script>
@using (Html.BeginForm("Index", "Home"))
{
    <h4>
        OPEN WINDOW</h4>
    <br />
    <div>
        <input type="submit" value="Click To Open" onclick="javascript:return openPopupWindow();" />
    </div>
}

In above code check the javascript function.

WELCOMEPAGE
@{
    ViewBag.Title = "WelcomePage";
}
<div>
    WELCOME</div>
<div>
    <h1>@ViewBag.PopupValue</h1>
</div>

In welcome I am displaying the value of viewbag.

Now we have done run the application to check the output.




Now click on button


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

0 comments:

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