I am using a radbutton. On the onclick event I have a piece of code that runs an SQL query to delete a record.
I want to return a confirm message box for this but I am not having any luck getting it to run.
- I have tried adding it to the onclientclick event,
- I have tried adding it to the attributes in the code behind when the button click event fires,
- and I have tried the
Page.RegisterStartupScript("clientScript", message).
Each one of these is deleting the account before the return confirm is executed.
I have commented out my delete code and the message will fire then. In the adding it to the attributes case, it worked after I pushed the delete button twice. I have been researching this for several days and have not found a suitable code yet. Any help would be appreciated.
Updated – added code.
Code I have tried:
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>
I finally found a piece of code that worked. I must have been entering some incorrect javascript.
Here is the code I found that worked for me.