Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to apply javascript on <asp:Buttonfield>?

I want to apply javascript on asp:buttonfield , when click on button then display message. Like Delete Button confirm message.

like image 494
Jd30814 Avatar asked Sep 04 '12 08:09

Jd30814


2 Answers

asp:ButtonField> tag does not have an OnClientClick.

Replace with Templated button

 <script type="text/javascript">
   function function()
   {
       return confirm("Are you sure you want to delete this?");
   }
</script>

...

<asp:TemplateField>
  <ItemTemplate>
     <asp:ImageButton ID="button" runat="server"
        OnClientClick="return function();" />
  </ItemTemplate>
</asp:TemplateField>
like image 57
Aghilas Yakoub Avatar answered Nov 02 '22 02:11

Aghilas Yakoub


In your page load, you could add

button.Attributes.Add("onclick", "confirm('are you sure? blah!')");
like image 37
Sherwin Avatar answered Nov 02 '22 02:11

Sherwin