4

Hi i got issue in opening pop-up window multiple times while clicking button. I will explain my issue clearly.

Customer Parent View

Hi, this is my parent view Customer Form.I have one add button near to Area if i enter the CustomerName AddressType, Street, Location,Place and then select the area.Suppose if area is not in the list means i have to add that. so i click that add button it will open AreaPartial view as popup window.

Area Partial View

After i enter the details and click the create button it will save the data in db and it shows the same popup window when it was close means when i click x mark[which is in the pop up window right top corner ) . Now all are working fine.

Now my issue is i open the pop-up window by clicking the button and add the area and close the pop-up window before clicking the main save button in parent view i have to add another one area so i click the add button again but it wont opening the pop-up window . This is my issue.

My Controller code to save the data which is entered in the partial view pop-up window

  public ActionResult AreaPartialView()
  {
    ViewBag.CityID = new SelectList(db.Cities, "CityID", "DisplayName");
    return View("AreaPartialView");
  }
   [HttpPost]

  public ActionResult AddAreaInfo(CustomerViewModel objareaVM)
   {
     var objAreaID = Guid.NewGuid();
     ViewBag.CityID = new SelectList(db.Cities, "CityID", "DisplayName", objareaVM.CityID);

     var ObjArea = new Area()
    {
    AreaID =objAreaID,
    DisplayName = objareaVM.Area,
    PrintName = objareaVM.Area,
    CityID = objareaVM.CityID,
    IsActive = true,
    IsDeleted = false,
    CreatedDate = DateTime.Now,
    EditedDate = DateTime.Now,
    LastActiveOn = DateTime.Now,
    RowID = Guid.NewGuid(),
    CreatedSessionID = Guid.NewGuid(),
    EditedSessionID = Guid.NewGuid(),
    OfflineMode = false,
    OfflineID = Guid.NewGuid()
    };

    db.Areas.Add(ObjArea);
    db.SaveChanges();
    ModelState.Clear();

  return Json(objAreaID);
   }

My j-query code to display the area partial view as popup window once the add button is clicked in Parent View

  <script src="~/Scripts/jquery-1.10.2-ui.js"></script>
  <link rel="stylesheet"href="http://code.jquery.com/ui/1.10.2/themes/smoothness/jquery-ui.css" />

  <script type="text/javascript">
   $("#AddArea").click(function () {
   $('#AddAreaNew').dialog("open");
   });
   $(function () {
   $('#AddAreaNew').dialog({
   autoOpen: false,
   width: 400,
   height: 500,
   resizable: false,
   title: 'Add Area',
   modal: true,
   open: function (event, ui) {
       $(this).load("@Url.Action("AreaPartialView", "Customer")");
   },
   buttons: {
       "Close": function () {
           $(this).dialog("close");
       }
    }
    });
    });

My Partial View code

   @Html.Label("Area" , new { @class = "control-label" })
   @Html.TextBoxFor(model => model.Area, new { @class = "form-control", type = "text" ,id ="AreaName"})
   @Html.ValidationMessageFor(model => model.Area)

   @Html.Label("City")        
   @Html.DropDownList("CityID", null, "Select", new { @class = "form-control " })

 <script src="~/Scripts/jquery-1.10.4-ui.min.js"></script>
 <link href="~/Content/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
 <script src="~/Scripts/jquery-ui-1.8.24.min.js"></script>
 <script type="text/javascript">

  function SaveArea() {
  debugger;
  var Area = $("#AreaName").val();
  var CityID = $("#CityID").val();
  alert(Area);
  var AreaAdd = { "Area": '' +Area + '', "CityID": CityID };
   $.post("/Customer/AddAreaInfo", AreaAdd, function(data) { 
    var option = new Option(Area, data);
        $('#AreaID').append($(option));
        alert("sucess");
        window.close();
  });
  }

This is my issue i cant able to open my pop-up window multiple times.i tried my level best to explain my issue. please any one help me to solve this issue.

Advance thanks..

Susan
  • 421
  • 2
  • 6
  • 21
  • Your best best may be to create a hidden div and create a class for it. Then once you have that, simply show or hide the div instead of using the dialog style of jquery. It may be causing some conflicts when you actually 'close' the dialog and removing the partial view all together. I would also take a look at using AJAX to post the data to your controller since you're already heavy utilizing JavaScript. I can give you an example if you'd like. – Dr Archer Apr 07 '16 at 05:03
  • Yes i need one example Dr_FeelGood – Susan Apr 07 '16 at 05:09
  • Since you are opening this dialog using jquery, you should use $('#AddAreaNew').dialog('close') instead of window.close() in your SaveArea() method. – Thangadurai Apr 07 '16 at 05:09
  • ok lets i have a try thangadurai – Susan Apr 07 '16 at 05:19
  • i gave as per you said thangadurai but it is not working.. – Susan Apr 07 '16 at 05:20
  • In your close dialog, are you also destroying the dialog? It is likely that the leftover artifacts of the first are are causing foul play. Actually, after destroying, you probably also want to remove it. Take a look at this answer: http://stackoverflow.com/a/8433251/550975 – Serj Sagan Apr 07 '16 at 05:53
  • one doubt where i have to give $(this).dialog('destroy').remove() in parent view or partial view serj – Susan Apr 07 '16 at 06:37

1 Answers1

0

Perhaps something like this would help you, as a brief example.

<style>
.floatingbox
{
z-index:99999;
position:absolute;
/* and more of your styling here, the main point is to make to appear above any other element on the page */
}
</style>

<div class="floatingbox" id="inputbox">

</div>

EDIT: <input type="button" value="Add Field" onclick="WhenIGetClicked(this)"/>

function WhenIGetClicked(e)
{
RefershContent();
document.getElementbyId('input').style.left = e.style.left;
document.getElementbyId('input').style.top = e.style.top; // show div at position of button but you can change it to where-ever
}

function RefreshContent()
{
 // put your html in here for the different fields you'll need in the div 
document.getElementbyId('inputbox').innerHTML = '';
// add the rest of your html mark up but make it as a function so it can be 'refreshed' and look like a new blank form each time, i found this easier than making a partial view and having to deal with loading it into the div/messing with javascript inside the partial view but may be personal preference :)
}

function OnSaveClick()
{
var SomeValueYouWantToPass = document.getElementbyId('inputboxinsidethediv').value; // or innerHTML works sometimes too if it's not getting the value correctly

$.ajax({
type:post,
url: '/MyController/ActionName',
dataType: 'json',
data: { MyVariableOnTheControllerSide: SomeValueYouWantToPass },
success: function()
{
alert('hey it worked!'); // or refresh the page to load the new field, etc
}
)}

}
</script>

On the controller side now:

public JsonResult UpdateField(string MyVariableOnTheControllerSide)
{
//do something with the data. 
return Json('Hey it worked!', JsonRequestBehavior.AllowGet);
}

If you'd like to pass it as a class since that's how you have it set up on your controller, you'll have to create the class as a Json object on the HTML markup side of it when grabbing the values (heck you could even do a for loop of the controls in the div and dynamically grab the values instead of reaching out to each element to get it's value). Very basic run down of how I usually do pop ups. Let me know if you need clarification or if I missed your point :)

Dr Archer
  • 348
  • 1
  • 3
  • 14