Presently, I have set up a popup confirm box to display as shown below:
However, the issue is that I am unsure whether the user clicked 'OK' or 'Cancel'.
ScriptManager.RegisterStartupScript(this, this.GetType(), "ajax", "<script language='javascript'>confirm('Do u wanna change?');</script>", false);
My goal is to achieve the following functionality:
if (originalId != 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;
}
}
Now, the question arises - how can I determine what option the user selected?
I attempted the following:
- I placed the code below in a folder1\jscrip.js file. Nevertheless, I am uncertain of how to call it due to the presence of an ajax update panel on the page, preventing me from using `ClientScript.RegisterClientScriptInclude` for referencing. This issue is discussed further at the 6th point in this link:
Page.ClientScript.RegisterClientScriptInclude("selective", ResolveUrl(@"folder1\jscrip.js"));
function confirmation()
{
if(confirm("Are you sure?")==true)
return true;
else
return false;
}
Any suggestions and insights would be greatly appreciated. Thank you.
Functionality:
The scenario involves the user clicking a button labeled "Save first". Upon doing so, it checks the condition of "if (orignalId != newId)". If this condition holds true, the confirm box appears; otherwise, no confirm box is displayed. Subsequently, if the user clicks 'OK', certain values are inserted into the database; otherwise, nothing happens.
Additional Code:
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 = "";
}
}
}