以下のように表示できるポップアップ確認ボックスがあります。
しかし、ユーザーが[OK]をクリックしたのか、[キャンセル]をクリックしたのかはわかりません。
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)」という条件をチェックします。これがtrueの場合、確認ボックスが表示されます。そうでない場合、確認ボックスは表示されません。ユーザーがクリックすると、 OKいくつかの値がDBに入力されているか、それ以外の場合は返され、何も実行されません
いくつかの追加コード:
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 = "";
}
}
}