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

No postback when click on a checkbox-cell in RadGrid

7 Answers 509 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anders
Top achievements
Rank 1
Anders asked on 27 Jan 2009, 08:56 AM

I’m using <ClientSettings EnablePostBackOnRowClick="True"> to do Codebehind stuff when the user click on a row in a RadGrid.

The first column in the RadGrid is a <GridTemplateColumn> that I have a checkbox in:

 

<radG:GridTemplateColumn Groupable="False" Reorderable="False" UniqueName="SelectColumn" AutoPostBackOnFilter="false" >

                        <HeaderTemplate>

                            <asp:CheckBox ID="chkCheckAll" runat="server" ToolTip="!Select/deselect all" />

                        </HeaderTemplate>

                        <ItemTemplate>

                            <asp:CheckBox ID="chkSelected" AutoPostBack="true" runat="server" OnCheckedChanged="chkSelected_CheckedChanged" />

                        </ItemTemplate>

                        <HeaderStyle Width="25px" />

                        <ItemStyle HorizontalAlign="Center"  />

                    </radG:GridTemplateColumn>

 

My problem is that I don’t want a postback when the checkbox column is checked. I also want the row to me selected when checking the checkbox.

7 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 27 Jan 2009, 11:47 AM
HI Anders,

You may consider using a GridClientSelectColumn for achieving the desired scenario. GridClientSelectColumn allows the user to select a row on the client side on clicking the CheckBox. For this you also have to set AllowRowSelect property to true in the ClientSettings.


ASPX:
<ClientSettings> 
           <Selecting  AllowRowSelect="True" /> 
    </ClientSettings> 

 <telerik:GridClientSelectColumn UniqueName="SelectColumn" ></telerik:GridClientSelectColumn> 


Thanks
Shinu
0
Pavlina
Telerik team
answered on 27 Jan 2009, 01:13 PM
Hi Anders,

I suggest you to use GridClientSelectColumn instead of GridTemplateColumn with CheckBox. In this case you will be able to select row when checking the checkbox without postback.

For more information see the following links:
Client-side row selection
Server-side row selection

Greetings,
Pavlina
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Anders
Top achievements
Rank 1
answered on 29 Jan 2009, 12:26 PM
The thing is that I want to have a postback when the client clicks on the row, but not a postback when the checkbox column is checked. I also got new directions about row selection:

1. Now the grid should only allow single row selection
2. When checking the checkboxes no row selcetions should be made.
0
Princy
Top achievements
Rank 2
answered on 29 Jan 2009, 01:57 PM
Hello Anders,

Try out the following code to disable row selection on clicking a checkbox. Also set the AllowMultiRowSelection to false to allow only single row selection.
aspx:
<telerik:RadGrid ID="RadGrid1" AllowMultiRowSelection="false" DataSourceID="SqlDataSource1" runat="server" > 
  <MasterTableView DataSourceID="SqlDataSource1" >       
      <Columns> 
          .....
      </Columns> 
  </MasterTableView> 
   <ClientSettings EnablePostBackOnRowClick="true"
      <ClientEvents OnRowSelecting="OnRowSelecting"   /> 
      <Selecting AllowRowSelect="True" /> 
   </ClientSettings> 
</telerik:RadGrid> 

js:
 function OnRowSelecting(sender, args)  
  {     
    var e = args.get_domEvent();      
    var targetElement = e.srcElement || e.target;                  
    //is the clicked element an input checkbox? <input type="checkbox"...>  
    if(targetElement.tagName.toLowerCase() != "input" && (!targetElement.type || targetElement.type.toLowerCase() != "checkbox")) 
    {  
        alert("Clicked on Row");  
    }  
    else  
    {  
        alert("Clicked on CheckBox"); 
        args.set_cancel(true);  
    }  
}  

Thanks
Princy.
0
Anders
Top achievements
Rank 1
answered on 30 Jan 2009, 06:56 AM
Noting happens on the call

var

e = args.get_domEvent();

where can I find what to do with the "args object".

 

0
Anders
Top achievements
Rank 1
answered on 30 Jan 2009, 01:11 PM
Now I've struggled with this all day.
What if I use <ClientSettings EnablePostBackOnRowClick="false"
and manually call a server function from javascript. Could that be possible?
0
Pavlina
Telerik team
answered on 30 Jan 2009, 06:39 PM
Hi Anders,

To get or set property values for client API properties, you must call property accessor methods that are named with the get_ and set_ prefixes. For example, to get or set a value for a property such as cancel, you call the get_cancel or set_cancel.

At client-side you can execute your own JavaScript functions at certain stages of the AJAX request. Additionally you can use a generic JavaScript function to make explicit AJAX requests to the server from the client.  

You can construct the javascript function to manually invoke Ajax request through the ajaxRequest() method of RadAjax.

More information is available in the following help articles:
OnRowSelected
Client-Side API

Regards,
Pavlina
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Anders
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Pavlina
Telerik team
Anders
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or