弹出窗口无法正常工作

时间:2015-07-02 15:38:08

标签: c# asp.net

我有一个.net页面,当代码隐藏文件中的某些条件不满足时,需要打开一个新的弹出窗口。我有以下代码:

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;
}

我提出了一个断点并对其进行了验证。它击中了线但弹出窗口没有打开。它只是移动到下一行并返回false。

我可以知道背后的原因吗?

@ yog2411这是检查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;
    }

1 个答案:

答案 0 :(得分:0)

尝试编写JS函数

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);
}

并在你的C#中

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

希望有所帮助