0

我正在使用 window.open 在弹出窗口中打开 2 个不同的页面,但由于某种原因,两个触发器都在弹出窗口中打开了相同的页面,这就是我尝试执行此操作的方法:

第一的:

Response.Write("<script type='text/javascript'>window.open('TransEditEntry.aspx','mywindow','width=850px,height=300px,left=0,top=10,screenX=100,screenY=10')</script>");

第二:

Response.Write(@"<script type='text/javascript'>window.open('TransNewEntry.aspx','','width=850px,height=300px,left=0,top=10,screenX=100,screenY=10')</script>");

这将打开“TransEditEntry.aspx”页面而不是“TransNewEntry.aspx”`

这里的其余代码:

单击添加按钮时调用的整个函数:

protected void addNew(object sender, EventArgs e)
    {
        //HiddenField sr = (HiddenField)GridView1.SelectedRow.Cells[6].FindControl("srno");
        //Session["TransSrNo"] = sr.Value;
        Response.Write(@"<script type='text/javascript'>window.open('TransNewEntry.aspx','','width=850px,height=300px,left=0,top=10,screenX=100,screenY=10')</script>");
        //Session["transAdd"] = "1";
    }

调用该函数的添加按钮:

<asp:Button ID="AddBtn" runat="server"  OnClick="addNew" Text="Add"/>

TransNewEntry.aspx.cs 页面

public partial class TransEditEntry : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection(GetConnectionString.Get());
    string subCode;
    DataTable dt;
    SqlDataAdapter sda;
    SqlCommandBuilder build;
    DataRow dr;
    DataSet ds = new DataSet();

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write((Session["TransSrNo"]).ToString());
        int SRno = Convert.ToInt32((Session["TransSrNo"]).ToString());
        con.Open();
        SqlCommand cmd3 = new SqlCommand("select sub_code from tran_dtls where sr_no='" + SRno + "'", con);
        subCode = (string)cmd3.ExecuteScalar();

        con.Close();
        if (!IsPostBack)
        {


            sda = new SqlDataAdapter("select * from tran_dtls where sr_no=" + SRno + "", con);
            build = new SqlCommandBuilder(sda);
            dt = new DataTable();
            sda.Fill(dt);
            foreach (DataRow row in dt.Rows)
            {
                srNoTxt.Text = "";
                amttxt.Text = "";
                partTxt.Text = "";
                checkNoTxt.Text = "";
                checkDtTxt.Text = "";
                refNoTxt.Text = "";
                refDtTxt.Text = "";
                jobNoTxt.Text = "";


            }

        }
    }

    protected void GlChange(object sender, EventArgs e)
    {
        con.Open();
        SqlCommand cmd4 = new SqlCommand("select ac_type from ac_mstr where AC_desc='" + GlDrp.SelectedValue + "'", con);
        string acType = (string)cmd4.ExecuteScalar();

        SqlCommand cmd5 = new SqlCommand("select gl_code from ac_mstr where AC_desc='" + GlDrp.SelectedValue + "'", con);
        string gl_code = (string)cmd5.ExecuteScalar();


        if (acType == "S")
        {
            SqlDataSource3.SelectCommand = ("select ac_desc from ac_mstr where gl_code='" + gl_code + "'");
            subDrp.DataBind();
            subDrp.Enabled = true;
            //Response.Write("<script type='javacript/text'>alert('1')</script>");
        }
        else
        {
            subDrp.Enabled = false;
            //Response.Write("<script type='javacript/text'>alert('2')</script>");
        }

        con.Close();
    }

    protected void saveRow(object sender, EventArgs e)
    {
        int SRno = Convert.ToInt32((Session["TransSrNo"]).ToString());


        sda = new SqlDataAdapter("select * from tran_dtls where tc='" + Session["TC"] + "' and doc_no='" + Session["docNo"] + "' ", con);
        build = new SqlCommandBuilder(sda);
        //dt = new DataTable();
        // DataSet ds = new DataSet();

        sda.Fill(ds);
        dt = (DataTable)ViewState["myViewState"];
        if (Session["gridRow"] == null)
        {
            dt = ds.Tables[0];


            dr = dt.NewRow();
            dr["GL_code"] = GlDrp.SelectedValue;
            dr["sub_code"] = subDrp.SelectedValue;
            dr["particulars"] = partTxt.Text;
            dr["chq_no"] = checkNoTxt.Text;
            dr["chq_dt"] = checkDtTxt.Text;
            dr["ref_no"] = refNoTxt.Text;
            dr["ref_dt"] = refDtTxt.Text;
            dr["dbcr"] = dbcrDrp.SelectedValue.ToString().Substring(0, 1);
            dr["amt"] = amttxt.Text;
            dr["job_no"] = jobNoTxt.Text;
            dr["EMP"] = empDrop.SelectedValue;
            dt.Rows.Add(dr);
            dt.AcceptChanges();
            ViewState["myViewState"] = dt;
            //Session["gridRow"] = dt;
            Session["gridRow"] = dt;
            Session["saveToggle"] = "1";
            closeFunction();
            Response.Write("<script type='text/javascript'>this.close()</script>");
        }

        else
        {
            dt = (DataTable)Session["gridRow"];
            dr = dt.NewRow();
            dr["GL_code"] = GlDrp.SelectedValue;
            dr["sub_code"] = subDrp.SelectedValue;
            dr["particulars"] = partTxt.Text;
            dr["chq_no"] = checkNoTxt.Text;
            dr["chq_dt"] = checkDtTxt.Text;
            dr["ref_no"] = refNoTxt.Text;
            dr["ref_dt"] = refDtTxt.Text;
            dr["dbcr"] = dbcrDrp.SelectedValue.ToString().Substring(0, 1);
            dr["amt"] = amttxt.Text;
            dr["job_no"] = jobNoTxt.Text;
            dr["EMP"] = empDrop.SelectedValue;
            dt.Rows.Add(dr);
            dt.AcceptChanges();
            ViewState["myViewState"] = dt;
            //Session["gridRow"] = dt;
            Session["gridRow"] = dt;
            Session["saveToggle"] = "1";
            //Response.Write("<script type='text/javascript'>window.opener.location.reload(true);</script>");
            closeFunction();
            Response.Write("<script type='text/javascript'>this.close()</script>");

        }
    }

    private void closeFunction()
    {
        StringBuilder sb = new StringBuilder();
        sb.Append("window.opener.RefreshPage();");
        sb.Append("window.close();");

        ClientScript.RegisterClientScriptBlock(this.GetType(), "CloseWindowScript", sb.ToString(), true);
    }
}
4

1 回答 1

0

检查您正在做的事情:Response.Write。必须先指出这两个条件>

于 2012-08-03T08:59:23.407 回答