我有一个弹出确认框,我可以显示如下。
但我不知道用户是单击确定还是取消。
ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax", "<script language='javascript'>confirm('Do u wanna change?');</script>", false);
所以我想做的就是这样。
if (orignalId != newId)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax", "<script language='javascript'>confirm('Do u wanna change?');</script>", false);
If (user clicks Yes)
{
add some data to SQL
}
else
{
return;
}
}
我怎么知道用户点击了什么?
我试过这个
- 我将下面的代码放在 folder1\jscrip.js 文件中,但我不知道如何调用它,因为我在页面中有一个使用过的 ajax 更新面板,所以我不能使用 ClientScript.RegisterClientScriptInclude 来引用它。如本链接第 6 点所述:http: //www.dotnetcurry.com/ShowArticle.aspx?ID=274
Page.ClientScript.RegisterClientScriptInclude("selective", ResolveUrl(@"folder1\jscrip.js"));
function confirmation()
{
if(confirm("Are you sure?")==true)
return true;
else
return false;
}
有什么建议吗???谢谢
功能:
所以用户点击一个名为“首先保存”的按钮,然后它检查条件“if(orignalId!= newId)”如果它是真的,则显示确认框,否则不显示确认框..现在如果用户点击好的,在数据库中输入了一些值,否则它只是返回并且什么都不做
一些额外的代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
else if (Label.Text != "")
{
Global.logger.Debug("Postback Happ, Label = " + Label.Text);
Button2_Click(sender, e);
}
}
protected void Button2_Click(object sender, EventArgs e)
{ if (orignalCsId != 0 && newCsId != 0)
{
if (orignalId != newId)
{
Global.logger.Debug("Pop Up crossed1");
ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax", String.Format(CultureInfo.InvariantCulture, @"__doPostback('{0}', confirm('Your Data From iD1 will be populated in iD2?').toString());", Label.Text), true);
}
else if (Page.Request["__EVENTTARGET"] == Label.Text)
{
Global.logger.Debug("__EVENTARGUMENT1 = " + Page.Request["__EVENTARGUMENT"]);
bool userClickedOK = Boolean.Parse(Page.Request["__EVENTARGUMENT"]);
if (userClickedOK)
{
// Add some data to SQL.
}
else
{
return;
}
Label.Text = "";
}
}
}