0

我在 GridView 中有一个按钮,单击它时会触发

protected void GridView_RowCommand(object sender, GridViewCommandEventArgs e)

事件。在那里我有一些逻辑,最后我正在注册一些生成弹出窗口的 javascript。我遇到的问题是确认弹出时出现。它在背景上显示一个空白屏幕,当我单击取消时它会再次显示它,否则它会导航到另一个页面......但是当框向上时,背景是白色的。

我需要让它像“警报”弹出窗口一样显示,仍然在后台显示网站。请注意,我只能使用这些弹出窗口来完成这项工作,因为它们在整个网站中都使用过(“不确认”)。这是我必须添加的第一个确认框,但其他页面上有很多警报。所以不想改变它们,因为它会做太多的工作(150 多页的网站)。

谢谢

4

1 回答 1

1

在警告框出现之前,页面似乎没有机会呈现。将显示 JavaScript 警报的代码连接到 body.onload 事件;这将在显示警报之前等待页面完成其初始加载。

            Page.ClientScript.RegisterClientScriptBlock(
                this.GetType(), 
                "key",
                @"
function Redirect() {
  location.href = 'shoppingCart.aspx';
}

function showAlert() {
  if (confirm('***Message truncated***.') == true){
    Redirect();
  };
}

// If you're using JQuery, you could do something like this, otherwise you
// would need to add the function call to the HTML body tag's onload attribute.
// There are other alternatives, see:
// http://stackoverflow.com/questions/1235985/attach-a-body-onload-event-with-js
$(document).ready(function() {
  showAlert();
});

", true);
于 2012-04-24T03:10:45.490 回答