asp.net mvc

Hi Guys,

I have asp.net mvc application and I'm trying to popup window from other popup window. I will explain step by step what I'm trying to do:

1. I have parent page which have button "Add item", when I click on this button I'm getting dialog box:

<div style="display:none;" class="info" title="*Enter Item Details" id="item_details">
    <table class="table table-responsive">
        <tr>
            <td>
                <div>
                    Item Description:@Html.TextBoxFor(m => m.itemDescription, new { @class = "form-control", @maxlength = 200 })
                </div>
            </td>
            <td>
                <div>
                    Lookup Code:@Html.TextBoxFor(m => m.lookup, new { @class = "form-control", @maxlength = 200 })
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div>
                    Quantity:  @Html.TextBoxFor(m => m.quatity, new { @class = "form-control", @onchange = "CalTotal();", @onkeypress = "return isNumberKey(event)", @onkeyup = "checkDec(this)", @maxlength = 12 })
                </div>
            </td>
            <td>
                <div>
                    Price: @Html.TextBoxFor(m => m.price, new { @class = "form-control", @onchange = "CalTotal();", @onkeypress = "return isNumberKey(event)", @onkeyup = "checkDec(this)", @maxlength = 12 })
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div>
                   @*Commodity Code: @Html.TextBoxFor(m => m.CommodityCode, new { @class = "form-control", @maxlength = 50, @placeholder = " Click F2 to get code", @onkeydown = "Showcom()" })*@
                    <input type="text" class="form-control" id="@Model.Id" value="@Model.CommodityCode" onkeydown="Showcom();" />
                </div>
            </td>
            <td valign="middle">
                <a class="btn btn-sm btn-primary" title="Add Item" href="#" onclick="return AddItemtoList();">Add</a>
            </td>
        </tr>
    </table>
</div>

Open in new window


script:
 function ItemDetailsWindow() {
            $('#itemDescription').val("");
            $('#lookup').val("");
            $('#price').val(0);
            $('#quatity').val(0);
            $('#total').val(0);
            $('#CommodityCode').val("");
            $("#item_details").dialog('open');
        }

Open in new window


After this dialog open I would like to popup through "commoditycode" textbox another window that will give me all the commodity code list by clicking F2 on my keyboard, to accomplish this goal I did something like this:

on the controller -
<input type="text" class="form-control" id="@Model.Id" value="@Model.CommodityCode" onkeydown="Showcom();" />

Open in new window


Script:
function Showcom(id) {
            if (event.which == 113) { //F2
                alter("what the fuck");
                var url = "@System.Configuration.ConfigurationManager.AppSettings["webUrl"]";
                url = url + "Ajax/Showcommoditycode";
                window.open(url, '_blank', 'resizable=yes');
            }
        }

Open in new window



The issue is - when I click F2 nothing popup.

Please Help.

Thanks ,
LVL 1
Moti Mashiah.NET DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Moti Mashiah.NET DeveloperAuthor Commented:
Hi Guys,

I solved the issue and I'm able to popup window now the only issue I'm facing now is to return value back to the text box from child to parent.

Here is my code:

This is how I open the child window:

 function Showcom() {
            if (event.which == 113) { //F2
                var url = "@System.Configuration.ConfigurationManager.AppSettings["webUrl"]";
                url = url + "Ajax/Showcommoditycode";
                window.open(url, '_blank', 'resizable=yes');
            }
        }

Open in new window


Then I return commodity code to commoditycode textbox:
controller
<td><a style="text-decoration: underline;" onclick="sendValues('@item.code');" href="#">@item.code</a></td>

Open in new window

script:
function sendValues(val) {
            window.opener.GetValueFromChild(val);
            window.close();
        }

Open in new window



Then getting the value in parents:

function GetValueFromChild(myVal) {
            $("#CommodityCode").val(myVal);
            $('#CommodityCode').focus();
        }

Open in new window

Moti Mashiah.NET DeveloperAuthor Commented:
Would like to mention one more thing. I'm opening the child window as dialog window.

function ItemDetailsWindow() {
            $('#itemDescription').val("");
            $('#lookup').val("");
            $('#price').val(0);
            $('#quatity').val(0);
            $('#total').val(0);
            $('#CommodityCode').val("");
            $("#item_details").dialog('open');
           
        }

Open in new window

Moti Mashiah.NET DeveloperAuthor Commented:
Issue has been solved:

Solution:

My dialog window:
<div style="display:none;" class="info" title="*Enter Item Details" id="item_details">
    <table class="table table-responsive">
        <tr>
            <td>
                <div>
                    Item Description:@Html.TextBoxFor(m => m.itemDescription, new { @class = "form-control", @maxlength = 200 })
                </div>
            </td>
            <td>
                <div>
                    Lookup Code:@Html.TextBoxFor(m => m.lookup, new { @class = "form-control", @maxlength = 200 })
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div>
                    Quantity:  @Html.TextBoxFor(m => m.quatity, new { @class = "form-control", @onchange = "CalTotal();", @onkeypress = "return isNumberKey(event)", @onkeyup = "checkDec(this)", @maxlength = 12 })
                </div>
            </td>
            <td>
                <div>
                    Price: @Html.TextBoxFor(m => m.price, new { @class = "form-control", @onchange = "CalTotal();", @onkeypress = "return isNumberKey(event)", @onkeyup = "checkDec(this)", @maxlength = 12 })
                </div>
            </td>
        </tr>
        <tr>
            <td>
                <div>
                   Commodity Code: @Html.TextBoxFor(m => m.CommodityCode, new { @class = "form-control", @maxlength = 50, @placeholder = " Click F2 to get code", @onkeydown = "Showcom()", id = "MyId" })
                 
                </div>
            </td>
            <td valign="middle">
                <a class="btn btn-sm btn-primary" title="Add Item" href="#" onclick="return AddItemtoList();">Add</a>
            </td>
        </tr>
    </table>
</div>

Open in new window

script:
function Showcom() {
            if (event.which == 113) { //F2
                var url = "@System.Configuration.ConfigurationManager.AppSettings["webUrl"]";
                url = url + "Ajax/Showcommoditycode";
                window.open(url, '_blank', 'resizable=yes');
            }
        }

Open in new window


get value fro child:

function GetValueFromChild(myVal) {
            $("#MyId").val(myVal);
            $("#MyId").focus();
          
        }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.