Confirm Message from Code Behind /

So, I needed to create some sort of confirm message box to present the user however I needed it to be all generated from the code behind. Below is an example of how this is done:

protected void Page_Load(object sender, EventArgs e)
{

string parameter = Request[“__EVENTARGUMENT”];
if (string.Equals(“confirmed”, parameter, StringComparison.InvariantCultureIgnoreCase))
{

//Call method to use if user clicks YES

}

//OR  – They both do the same thing however when the above doesnt work, use the following:

if (!string.IsNullOrEmpty(Request[“__EVENTARGUMENT”]) && Request[“__EVENTARGUMENT”].ToLower().Equals(“confirmed”))
{

//Call method to use if user clicks YES

}

}

And finally wherever you need to send the confirm message, lets say in a normal method:

public void AskConfirmation()

{

 ScriptManager.RegisterStartupScript(this, this.GetType(),”temp”, “if(confirm(‘Are you sure ?’)) __doPostBack(‘ ‘, ‘confirmed’);”, true);

//If the user clicks yes, the method called in the PageLoad will be fired

}

Thats All 🙂 enjoy