弹出窗口不起作用
本文关键字:不起作用 窗口 | 更新日期: 2023-09-27 18:00:47
我有一个.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这是检查是否有效的代码
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);
希望它能帮助