簡體   English   中英

彈出窗口不起作用

[英]Pop-up window not working

我有一個.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;
    }

嘗試編寫一個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);

希望能幫助到你

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM