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

Bind checkbox in Template Column - and client side OnCommand

3 Answers 131 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Declan
Top achievements
Rank 2
Declan asked on 02 Oct 2008, 02:21 PM
I have read and used info from this thread and all works just fine.

However I now need to trap, at client side, if the user clicks the "Add new row" link on the grid. To do this I added

<ClientSettings> 
    <ClientEvents  OnCommand="RaiseCommand" /> 
</ClientSettings> 

to my grid and then added some javascript to process the event:

    function RaiseCommand(sender, args) { 
 
        var cmd = args.get_commandName(); 
 
        if (cmd = 'InitInsert') { 
            var message = "Add new clicked.\n" + 
                    "Click OK to continue or Cancel to change your selection.\n"
            if (!confirm(message)) 
                return args.set_cancel(true
            else 
                return args.set_cancel(false); 
        } 
    } 

The javascript traps the event but the result is that the ItemCommand event at the server does not fire and the new default values for the check boxes are not set resulting in an error "Conversion from type DBNull to type Boolean is not valid".

If I remove the javascript I can add new rows without error and the ItemCommand event fires setting the default checkbox values.




3 Answers, 1 is accepted

Sort by
0
Declan
Top achievements
Rank 2
answered on 02 Oct 2008, 02:48 PM
Perhaps I should explain what I am trying to achieve:

Under certain circumstances a user may be limited to the maximum number of rows they can add to a grid. After each save I store the number of rows already in the grid in a hidden label.

If the user clicks "add row" and the condition is met I need to check the number of rows already in the grid by checking the value in the label. If it is at the max allowed then I wish to popup a message warning the user but with an option to continue.
0
Declan
Top achievements
Rank 2
answered on 03 Oct 2008, 02:55 PM
If I trap OnCommand at the client does this prevent ItemCommand event firing on the server?
0
Declan
Top achievements
Rank 2
answered on 03 Oct 2008, 04:32 PM
A solution that seems to work:

   <CommandItemTemplate> 
        <asp:LinkButton runat="server" ID="AddNew" Text="Add new record"  
            CommandName="InitInsert"  
            OnClientClick="javascript:return CheckAddNew();"
        </asp:LinkButton> 
   </CommandItemTemplate> 

Calling javascript:
 function CheckAddNew() 
        { 
        var message='You are about to add a new row. Are you sure?'
        if(!confirm(message)){return false;} 
        } 
Tags
Grid
Asked by
Declan
Top achievements
Rank 2
Answers by
Declan
Top achievements
Rank 2
Share this question
or