• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 636
  • Last Modified:

javascript window.open opens the new window behind the parent

I am using this statement in code behind to open a help window:

Page.RegisterStartupScript("showHelp", "<script>var w=window.open('showHelp.aspx?helpID=invoiceAdd.aspx','', 'width=455,height=200,top=200,left=200,scrollbars=yes,resizeable=yes');</script>");

On some most pages the window pops up in front as expected.  However on a handful of my pages, the help window pops open and then the parent window comes back in front.  

Thanks for any help.
0
mastertrac
Asked:
mastertrac
  • 4
  • 2
  • 2
  • +1
1 Solution
 
Tommie Nathaniel Carter, Jr., MBACommented:
Can you add the language attribute to the script header?
<script language=javascript>

Please change, note effect and report back.
Tommie
0
 
mastertracAuthor Commented:
Changed it to: Page.RegisterStartupScript("showHelp", "<script language=javascript>var w=window.open('showHelp.aspx?helpID=invoiceAdd.aspx','', 'width=455,height=200,top=200,left=200,scrollbars=yes,resizeable=yes');</script>");

Same result.  Thanks for your help.
0
 
SirCroftyCommented:
try adding this to the end of script:

w.focus();
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
SirCroftyCommented:
So you would have this:

Page.RegisterStartupScript("showHelp", "<script>var w=window.open('showHelp.aspx?helpID=invoiceAdd.aspx','', 'width=455,height=200,top=200,left=200,scrollbars=yes,resizeable=yes');w.focus();</script>");
0
 
mastertracAuthor Commented:
I sure thought that work, SirCrofty, but no dice.  Here is my aspx code in case that helps.  The one thing that seems to be constant is, if there is a GridView or a FormView,  the help button works.  On pages like this with just a table, it doesn't.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="invoiceAdd.aspx.cs" Inherits="addInvoice" StylesheetTheme="Blue" %>

<%@ Register Assembly="BasicFrame.WebControls.BasicDatePicker" Namespace="BasicFrame.WebControls"
    TagPrefix="BDP" %>

<%@ Register Src="pbtHeader.ascx" TagName="pbtHeader" TagPrefix="uc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Add Invoice</title>
</head>
<body bottommargin="5" leftmargin="5" rightmargin="5" topmargin="5">
    <form id="form1" runat="server">
    <div>
        <uc1:pbtHeader ID="PbtHeader1" runat="server" />
   
    </div>
        <table style="clear: none; z-index: 102; left: 129px; position: absolute; top: 152px">
            <tr>
                <td class="bannerForm">
                    &nbsp;Add New
                        Invoice
                        <asp:ImageButton ID="ImageButton2" runat="server" ImageUrl="~/Img/help.gif" OnClick="ImageButton1_Click"
                            Style="z-index: 103; left: 434px; position: absolute; top: 6px" />
                   
                </td>
            </tr>
            <tr>
                <td style="border-right: 3px ridge; border-left: 3px ridge; width: 450px; border-bottom: 3px ridge" class="formBody">
                    <table id="TABLE1" onclick="return TABLE1_onclick()" width="450">
                        <tr>
                            <td colspan="2" style="height: 21px">
                                <span><strong>Fill in the following fields to start a new invoice.</strong></span></td>
                        </tr>
                        <tr>
                            <td align="right">
                                Customer Name:&nbsp;
                            </td>
                            <td>
                                <asp:DropDownList ID="custDropDownList" runat="server" DataSourceID="customerDataSource"
                                    DataTextField="Company" DataValueField="CustomerID">
                                </asp:DropDownList>&nbsp;
                                <asp:LinkButton ID="customerLink" runat="server">Add Customer</asp:LinkButton></td>
                        </tr>
                        <tr>
                            <td align="right">
                                Terms:&nbsp;
                            </td>
                            <td>
                                <asp:DropDownList ID="termsDropDownList" runat="server" DataSourceID="termsDataSource"
                                    DataTextField="Description" DataValueField="Description">
                                </asp:DropDownList>&nbsp;
                                <asp:LinkButton ID="termsLink" runat="server">Add Terms</asp:LinkButton></td>
                        </tr>
                        <tr>
                            <td align="right">
                                Tax:
                            </td>
                            <td>
                                <asp:DropDownList ID="salesTaxDropDownList" runat="server" DataSourceID="salesTaxDataSource"
                                    DataTextField="Description" DataValueField="TaxRateID">
                                </asp:DropDownList>&nbsp;
                                <asp:LinkButton ID="taxRateLink" runat="server">Add Tax Rates</asp:LinkButton></td>
                        </tr>
                        <tr>
                            <td align="right">
                                Ship Date:&nbsp;</td>
                            <td>
                                <BDP:BDPLite ID="shipDatePicker" runat="server">
                                    <TextBoxStyle Width="80px" />
                                </BDP:BDPLite>
                            </td>
                        </tr>
                        <tr>
                            <td align="right">
                                Invoice Date:&nbsp;</td>
                            <td>
                                <BDP:BDPLite ID="invoiceDatePicker" runat="server">
                                    <TextBoxStyle Width="80px" />
                                </BDP:BDPLite>
                                &nbsp;&nbsp;</td>
                        </tr>
                        <tr>
                            <td align="right">
                                PO #:
                            </td>
                            <td>
                                <asp:TextBox ID="poNumberTextBox" runat="server"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <td align="right">
                                Ref# / Job#:
                            </td>
                            <td>
                                <asp:TextBox ID="customerJobTextBox" runat="server"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <td align="right">
                                &nbsp;Ship Via:
                            </td>
                            <td>
                                <asp:TextBox ID="shipViaTextBox" runat="server"></asp:TextBox></td>
                        </tr>
                        <tr>
                            <td align="left" style="height: 21px">
                            </td>
                            <td style="height: 21px">
                                <asp:Button ID="submitButton" runat="server" OnClick="submitButton_Click" Text="Create Invoice" />
                                <asp:Button ID="Button1" runat="server" PostBackUrl="~/Invoices.aspx" Text="Cancel" /></td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <asp:SqlDataSource ID="customerDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:xMissionMSsql %>"
            SelectCommand="SELECT Company, CustomerID FROM dbo.Customer WHERE (CompanyID = @CompanyID) UNION SELECT '' AS company, null AS CustomerID ORDER BY Company">
            <SelectParameters>
                <asp:SessionParameter Name="CompanyID" SessionField="UserCompanyID" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
        <asp:SqlDataSource ID="termsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:xMissionMSsql %>"
            SelectCommand="SELECT Description, TermsID FROM dbo.Terms WHERE (CompanyID = @CompanyID) UNION SELECT '' AS Description, null AS TermsID ORDER BY Description">
            <SelectParameters>
                <asp:SessionParameter Name="CompanyID" SessionField="UserCompanyID" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource><asp:SqlDataSource ID="salesTaxDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:xMissionMSsql %>"
            SelectCommand="SELECT TaxRateID, Description, Rate FROM TaxRateView WHERE (CompanyID = @CompanyID) UNION SELECT 0 AS TaxRateID, 'No Tax' AS Description, 0 AS Rate">
            <SelectParameters>
                <asp:SessionParameter Name="CompanyID" SessionField="UserCompanyID" Type="Int32" />
            </SelectParameters>
        </asp:SqlDataSource>
    </form>
</body>
</html>
0
 
mastertracAuthor Commented:
I guess I should post the c# code as well:

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class addInvoice : System.Web.UI.Page
{
    string cnString = ConfigurationManager.ConnectionStrings["xMissionMSsql"].ConnectionString;
    protected void Page_PreInit(object sender, EventArgs e)
    {
        if (Session["UserTheme"] != null)
        {
            Theme = Session["UserTheme"].ToString();
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        custDropDownList.Focus();
        invoiceDatePicker.SelectedDate = ebGlobal.ebGMTtoNow(Convert.ToInt32(Session["UserGMTOffset"]));
        shipDatePicker.SelectedDate = ebGlobal.ebGMTtoNow(Convert.ToInt32(Session["UserGMTOffset"]));
    }
    protected void submitButton_Click(object sender, EventArgs e)
    {
        //now check for company dup
        int theresAProb = 0;
        if (custDropDownList.SelectedValue == null)
        {
            theresAProb = 1;
            this.RegisterClientScriptBlock("alertMsg", "<script>alert('You must select a customer before creating the invoice.');</script>");
        }
        if (termsDropDownList.SelectedValue == null)
        {
            theresAProb = 1;
            this.RegisterClientScriptBlock("alertMsg", "<script>alert('You must select the terms before creating the invoice.');</script>");
        }
        // check for valid dates
        // get the next invoice#
        int invcNumber = 0;
        try
        {
            invcNumber = 1 + Convert.ToInt32(ebGlobal.ebScalar("select max(invoicenumber) from invoice where companyid = " + Session["UserCompanyID"]));
        }
        catch
        {
            invcNumber = Convert.ToInt32(ebGlobal.ebScalar("select invoiceNumber from company where companyid = " + Session["UserCompanyID"]));
        }
        if (theresAProb == 0)
        {
            // if the fields are all filled in then do the database save and mail send code
            SqlConnection bAddConn = null;
            SqlCommand bAddComm = null;
            try
            {
                decimal trDec;
                try
                {
                    trDec = Convert.ToDecimal(ebGlobal.ebScalar("select rate from TaxRateView where TaxRateID = " + salesTaxDropDownList.SelectedValue));
                }
                catch
                {
                    trDec = 0;
                }
                bAddConn = new SqlConnection(cnString);
                bAddComm = new SqlCommand("INSERT into Invoice (TaxRateID, CustomerJob, ShipVia, poNumber, InvoiceTaxRate, InvoiceNumber, CompanyID, CustomerID, Shipped, InvoiceDate, InvoiceTerms) " +
                "VALUES(@trID, @CustomerJob, @shipVia, @poNum, @TaxRate, @invcNum, @coID, @cusID, @shipDate, @invcDate, @InvcTerms) Select SCOPE_IDENTITY()", bAddConn);

                //Create the parameters here
                bAddComm.Parameters.AddWithValue("@trID", Convert.ToInt32(salesTaxDropDownList.SelectedValue));
                bAddComm.Parameters.AddWithValue("@CustomerJob", customerJobTextBox.Text);
                bAddComm.Parameters.AddWithValue("@shipVia", shipViaTextBox.Text);
                bAddComm.Parameters.AddWithValue("@poNum", poNumberTextBox.Text);
                bAddComm.Parameters.AddWithValue("@TaxRate", trDec);
                bAddComm.Parameters.AddWithValue("@invcNum", invcNumber);
                bAddComm.Parameters.AddWithValue("@coID", Session["UserCompanyID"].ToString());
                bAddComm.Parameters.AddWithValue("@cusID", custDropDownList.SelectedValue);
                bAddComm.Parameters.AddWithValue("@shipDate", shipDatePicker.SelectedDate);
                bAddComm.Parameters.AddWithValue("@invcDate", invoiceDatePicker.SelectedDate);
                bAddComm.Parameters.AddWithValue("@InvcTerms", termsDropDownList.SelectedValue);
                bAddConn.Open();
                int newInvoiceID = Convert.ToInt32(bAddComm.ExecuteScalar());
                bAddConn.Close();
                Session["passID"] = newInvoiceID.ToString();
                Response.Redirect("Invoice.aspx");
            }
            finally
            {
                bAddConn.Close();
            }
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        //Page.RegisterStartupScript("showHelp", "<script language=javascript>var w=window.open('showHelp.aspx?helpID=invoiceAdd.aspx','', 'width=455,height=200,top=200,left=200,scrollbars=yes,resizeable=yes');</script>");
        Page.RegisterStartupScript("showHelp", "<script>var w=window.open('showHelp.aspx?helpID=invoiceAdd.aspx','', 'width=455,height=200,top=200,left=200,scrollbars=yes,resizeable=yes');w.focus();</script>");
    }
}
0
 
gnoonCommented:
Hi mastertrac,

The code is seem to be fine but ..
Many possible cases can cause the popup goes behind its parent
 - Your mouse triggers twice, and to happen the 2nd triggers on the parent page
 - Maybe there a javascript code inside the pbtHeader control to bring itself active
 - Try with Page.RegisterClientScriptBlock instead of Page.RegisterStartupScript
 - Try to dalay popup time after page load for a few seconds
   Page.RegisterStartupScript("showHelp", "<script>setTimeout(function(){var w=window.open('showHelp.aspx?helpID=invoiceAdd.aspx','', 'width=455,height=200,top=200,left=200,scrollbars=yes,resizeable=yes');w.focus();}, 300/*milisecs*/);</script>");

If the solutions above do not solve, please post the View Source code of the page.

Regards,
G
0
 
mastertracAuthor Commented:
Thank you everyone.  gnoon you must be a true javascript guru.  The millisecs did the trick.  I actually have them set at 50 and everything works fine.

Mark
0
 
gnoonCommented:
>everything works fine
glad to hear that :)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now