【问题标题】:How can i close window and relaod in asp.net我如何关闭窗口并在 asp.net 中重新加载
【发布时间】:2021-06-15 21:23:30
【问题描述】:

我的代码如下所示。

protected void btnApprove_Click(object sender, EventArgs e)
{
    if (id == "Button2")
    {
        string sql = @"update AdjTranSeqDetails set Approver1Status = 'Rejected',finalStatus='Rejected' ,updatedtime = GETDATE(),Approver1Comment ='{1}',modifieduser = '{2}' where TranSeq ={0}";
        sql = String.Format(sql, tbxTranSeq.Text, TextBox2.Text, Master.CurrentUser);
        string sql2 = @"INSERT INTO AdjTranSeqDetailsHistory SELECT * FROM AdjTranSeqDetails WHERE tranSeq={0}";
        sql2 = String.Format(sql2, tbxTranSeq.Text);
        string sql3 = @"delete from AdjTranSeqDetails where tranSeq={0}";
        sql3 = String.Format(sql3, tbxTranSeq.Text);
        if (dba.SqlUpdate(sql, ref ex, ref rowCt) || dba.SqlInsert(sql2, ref ex, ref rowCt) ||dba.SqlDelete(sql3, ref ex, ref rowCt))
        {
            string sscript = "<script language=\"Jscript\" > ";
            if (Master.PageMode == "View")
            {
                sscript += "if (window.opener && !window.opener.closed) ";
                sscript += "{window.opener.DoSearch();}";
            }
            sscript += "window.opener='x';self.close();";
            sscript += "</Script>";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "SelfClose", sscript);

        }
    }
    updateapp();
    GetBillTranInfo();
}

像 Button2 一样,有 10 个按钮。如果一个 if 条件函数完成,我需要关闭窗口并需要重新加载页面。我可以这样做吗?

我已经尝试过上面的方法,但这对我不起作用。

【问题讨论】:

    标签: sql asp.net aspxgridview


    【解决方案1】:

    在我的用户控件中,更新数据后我会这样做:

    Response.Redirect(Request.RawUrl);    
    

    这确保了页面被重新加载,并且在用户控件中可以正常工作。您使用 RawURL 而不是 Request.Url.AbsoluteUri 来保留请求中可能包含的任何 GET 参数。

    您可能不想使用:__doPostBack,因为许多 aspx 页面在回发时表现不同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-11
      • 1970-01-01
      • 2013-09-15
      • 1970-01-01
      相关资源
      最近更新 更多