简体   繁体   中英

Pop-up window not working

I have a .net page which needs to open a new pop-up window when certain conditions are not met in the code behind file. I have the following code:

private bool isValidPart(string partNo)
{
    if (!string.IsNullOrEmpty(partNo))
    {
        DataBase.DBManager dm = new DBManager();

        if (!Convert.ToBoolean(dm.ExecScalar("usp_getPart", partNo)))
        {
            string url = "test.aspx";
            string s = "window.open('" + url + "', 'popup_window', 'width=300,height=100,left=100,top=100,resizable=yes');";
            ClientScript.RegisterStartupScript(this.GetType(), "script", s, true);
            return false;
        }
    }
    return true;
}

I put a break point and verified it. It hits the line but the pop-up window does not open up. It just simply moves to next line and returns false.

May I please know the reason behind it?


@yog2411 This is the code which checks that isvalidpart()

                                             private bool SetRowData()
    {
        int rowIndex = 0;
        if (ViewState["CurrentData"] != null)
        {
            DataTable dtCurrentData = (DataTable)ViewState["CurrentData"];
            DataRow drCurrentRow = null;
            if (dtCurrentData.Rows.Count > 0)
            {
                for (int i = 1; i <= dtCurrentData.Rows.Count; i++)
                {
                    TextBox TextCustomerName = (TextBox)gvInventory.Rows[rowIndex].Cells[1].FindControl("txtCustomerName");
                    TextBox TextPONumber = (TextBox)gvInventory.Rows[rowIndex].Cells[2].FindControl("txtPONumber");
                    TextBox TextPartNumber = (TextBox)gvInventory.Rows[rowIndex].Cells[3].FindControl("txtPartNumber");
                    TextBox TextQuantity = (TextBox)gvInventory.Rows[rowIndex].Cells[4].FindControl("txtQuantity");
                    //TextBox TextReqShipDate = (TextBox)gvInventory.Rows[rowIndex].Cells[5].FindControl("txtReqShipDate");
                    if (!isValidPart(TextPartNumber.Text))
                        return false;
                    drCurrentRow = dtCurrentData.NewRow();
                    drCurrentRow["RowNumber"] = i + 1;
                    dtCurrentData.Rows[i - 1]["CustName"] = TextCustomerName.Text; 
                    dtCurrentData.Rows[i - 1]["PONum"] = TextPONumber.Text;
                    dtCurrentData.Rows[i - 1]["PartNum"] = TextPartNumber.Text;
                    dtCurrentData.Rows[i - 1]["Qty"] = TextQuantity.Text;
                   // dtCurrentData.Rows[i - 1]["ReqShipDate"] = TextReqShipDate.Text;                     
                    rowIndex++;                      
                }
                ViewState["CurrentData"] = dtCurrentData;
                gvInventory.DataSource = dtCurrentData;
                gvInventory.DataBind();}
        }
        SetPreviousData();
        return true;
    }

try writing a JS function

function showMyPopUp(myUrl) {
    //I have this settings and it works like a popUp, 
    //I just going to write the properties you have, but you can change them for these ones
    //var CustomFeatures = 'titlebar=no, status=no,menubar=no,resizable=no,scrollbars=no,toolbar=no,location=no,width=300,height=100,top=100,left=100';
    var CustomFeatures = 'resizable=yes,width=300,height=100,top=100,left=100';
    window.open(myUrl, '_blank', CustomFeatures, true);
}

and in your C# this

string url = "test.aspx";
string myCallfunction = "showMyPopUp('" + url + "');"
ScriptManager.RegisterStartupScript(this, this.GetType(), "Funct", myCallfunction , true);

hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM