I am currently working with a radbutton that triggers an SQL query to delete a record on its onclick event.
My goal is to display a confirmation message box before the deletion process, but I'm encountering difficulties in making it work as intended.
- I attempted adding the confirm dialog to the onclientclick event,
- I tried incorporating it into the attributes using code behind when the button click event occurs,
- and I also experimented with
.Page.RegisterStartupScript("clientScript", message)
Unfortunately, each of these methods results in the account being deleted prior to the confirmation prompt appearing.
When I temporarily disable the delete code, the message pops up successfully. In the case of adding it to the attributes, the confirmation only worked after clicking the delete button twice. Despite researching extensively for several days, I have not discovered a suitable solution yet. Any assistance would be greatly appreciated.
Updated - included code.
Various approaches I have tested:
string message = "<script language=JavaScript> alert( ' The ' );</script>";
if (!Page.IsStartupScriptRegistered("clientScript"))
{
Page.RegisterStartupScript("clientScript", message);
}
And
RadButton btn = (RadButton)sender;
string strMessage = "Are you sure?";
btn.Attributes.Add("onclick", "return confirm('" + strMessage + "');");
Here is the button
<telerik:RadButton ID="btnDeleteAccount" runat="server" Font-Bold="True" Font-Names="Arial"
Font-Size="11px" Skin="WebBlue" Text="Delete Account" OnClick="btnDeleteAccount_Click"
Width="150px">
</telerik:RadButton>