This is a migrated thread and some comments may be shown as answers.

OnClientClick event not work in grid itemtemplete

1 Answer 204 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rahul
Top achievements
Rank 1
Rahul asked on 11 Feb 2014, 11:06 AM
Hi want to call client side function than server side call on link button in side grid item template. but when use a OnClientClick event on link button they not work well please provide solutions.
My code as follows :
client side code is:
 function permission() {        
          var add =1;
          if (add == 0) {
                                   alert("You have no permissions to Update Record"); return false; }
          else { return true; }
      }

  <telerik:GridTemplateColumn AllowFiltering="false" UniqueName="Action" HeaderText="Action" ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left">
                                                                        <ItemTemplate>
                                                                            <telerik:RadButton ButtonType="LinkButton" runat="server" ID="btnEdit" 
                                                                                ToolTip="EditRecord"  Text="Edit" CommandName="EditButton" 
                                                                                CommandArgument='<%# Eval("LandlordId") %>' onClientClicked="chkpermissionsEdit"   />
                                                                            <telerik:RadButton ButtonType="LinkButton"  runat="server" ID="btnDelete" ToolTip="DeleteRecord"  Text="Delete" CommandName="DeleteButton" CommandArgument='<%# Eval("LandlordId") %>' />
                                                                        </ItemTemplate>
                                                                        <HeaderStyle HorizontalAlign="Left" />
                                                                        <ItemStyle HorizontalAlign="Left" />
                                                                    </telerik:GridTemplateColumn>

1 Answer, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 14 Feb 2014, 08:29 AM
Hello Rahul,

I could only assume that the problem you are experiencing is that the return false does not prevent the postback, which is expected. 

What I could suggest is that you set the AutoPostBack property of the button to false and change the function handling the OnClientClicked event with the following:
<telerik:RadButton ButtonType="LinkButton" runat="server" ID="btnEdit" OnClientClicked="checkPermission"
    ToolTip="EditRecord" Text="Edit" CommandName="EditButton" AutoPostBack="false"
    CommandArgument='<%# Eval("ID") %>'/>
And the JavaScript:
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function checkPermission(sender, args) {
            var add = 1; //
 
            if (add == 0) {
                alert("You have no permissions to Update Record");
                return false;
            }
            else {
                var grid = $find("<%=RadGrid1.ClientID%>");
                grid.get_masterTableView().fireCommand(args.get_commandName(), args.get_commandArgument());
            }
        }
    </script>
</telerik:RadCodeBlock>

Hope that helps.


Regards,
Konstantin Dikov
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Rahul
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Share this question
or