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

How to disable a Control inside CommandItemTemplate in Client Side.

10 Answers 537 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Anto (DLL Version : 2008.3.1314.35) asked on 06 Jul 2010, 08:01 AM
Hi All

Have a Grid with some records, which works fine.

Have included a RadToolBar inside CommandItemTemplate of the Grid, which contains two RadToolBarButton "Edit" and "Close".

While I am selecting a row in the grid, Need to check a field "Termination Status", If it is not equal to "T" then need to disable the RadToolBarButton "Edit" in RadToolBar. Need to do it in Client Side.

                                       <CommandItemTemplate> 
                                            <div> 
                                                <table width="103%" border="0" cellpadding="0" cellspacing="0" style="margin-top: -2px; 
                                                    margin-left: -4px; margin-bottom: -3px;"> 
                                                    <tr> 
                                                        <telerik:RadToolBar runat="server" ID="RTBTermination" Skin="Office2007" Width="100%" 
                                                            OnClientButtonClicked="RTBTerminationclientButtonClicked" OnButtonClick="RTBTermination_ButtonClick"
                                                             
                                                            <Items> 
                                                                <telerik:RadToolBarButton Text="Edit" Font-Size="9" ForeColor="#00156E" CommandName="Edit" 
                                                                    ImagePosition="Left" ImageUrl="images/penedit.png"
                                                                </telerik:RadToolBarButton> 
                                                                 
                                                                <telerik:RadToolBarButton Text="Close" Font-Size="9" ForeColor="#00156E" ImagePosition="Left" 
                                                                    ImageUrl="images/closeeeeeee.gif"
                                                                </telerik:RadToolBarButton> 
                                                                <telerik:RadToolBarButton Text="" Font-Size="9" Width="800px" Enabled="false" ForeColor="#00156E"
                                                                </telerik:RadToolBarButton> 
                                                            </Items> 
                                                        </telerik:RadToolBar> 
                                                    </tr> 
                                                </table> 
                                            </div> 
                                        </CommandItemTemplate> 


Have used the RowSelect in Client Side

function rgvReport_RowSelect(sender, eventArgs) { 
                var rowindex = eventArgs.get_itemIndexHierarchical(); 
                document.getElementById("<%=txtrgvReportRowIndex.ClientID%>").value = eventArgs.get_itemIndexHierarchical(); 
                //alert(rowindex); 
                var TerGrid = $find("<%=rgvReport.ClientID %>"); 
                var gridRow = TerGrid.MasterTableView.get_dataItems()[rowindex]; 
                var TerStatus = gridRow.getDataKeyValue("TerminationStatus");                  
                
                //alert(TerStatus); 
                //alert(RTBButton); 
 
            } 

Is there any option to solve this problem

Thanking You

-Anto

10 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 06 Jul 2010, 09:09 AM
Hello Anto,

You can access the RadToolBar control using the findControl method from our static client-side library:
Telerik static client library

...
var gridRow = TerGrid.get_masterTableView().get_dataItems()[rowindex];
var radToolBar = $telerik.findControl(TerGrid.get_element(), "RTBTermination");
...

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 10 Jul 2010, 08:01 AM
Hi Daniel,

Here I have taken the RadToolBar, Its ok.

Good Job.

But I need to disable the RadToolBarButton with Text="Edit" which does not have an ID. And it is inside the items of RadToolBar.

Thank You

-Anto

0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 13 Jul 2010, 04:13 PM
Hi Daniel,

I used the code in many ways, But not able to get the RadToolBarButton with Text="Edit".

<telerik:RadToolBarButton Text="Edit" Font-Size="9" ForeColor="#00156E" CommandName="Edit"
                                                                    ImagePosition="Left" ImageUrl="images/penedit.png">
                                                                </telerik:RadToolBarButton>


Is there any option to get the RadToolBarButton.

Thank You

-Anto
0
Daniel
Telerik team
answered on 15 Jul 2010, 08:58 AM
Hello Anto,

This is a sample code that shows how to disable this button on page load. Please replace RadGrid1 with the actual ID of your RadGrid.
<script type="text/javascript">
    function pageLoad()
    {
        var radGrid = $get("RadGrid1");
        var radToolBar = $telerik.findControl(radGrid, "RTBTermination");
        radToolBar.get_items().getItem(0).set_enabled(false);
    }
</script>

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 15 Jul 2010, 12:58 PM
Hi  Daniel

I have given as you have mentioned.

function rgvReport_RowSelect(sender, eventArgs) {
                var rowindex = eventArgs.get_itemIndexHierarchical();
                document.getElementById("<%=txtrgvReportRowIndex.ClientID%>").value = eventArgs.get_itemIndexHierarchical();
                //alert(rowindex);
                var TerGrid = $find("<%=rgvReport.ClientID %>");
                var gridRow = TerGrid.MasterTableView.get_dataItems()[rowindex];
                var TerStatus = gridRow.getDataKeyValue("TerminationStatus");
                var radToolBar = $telerik.findControl(gridRow.get_element(), "RTBTermination");              
                if (TerStatus != "Termination Request") {
                    
                    radToolBar.get_items().getItem(0).set_enabled(false);
                }
                else {
                    radToolBar.get_items().getItem(0).set_enabled(true);
                }
            }


But I get an error:

Microsoft JScript runtime error: 'null' is null or not an object

in the new line added,

radToolBar.get_items().getItem(0).set_enabled(false);

-Anto
0
Accepted
Daniel
Telerik team
answered on 21 Jul 2010, 08:53 AM
Hello Anto,

Your RadToolBar control resides in the CommandItem, not in the DataItem. This means that you should pass (to the findControl function) an element that is parent to the CommandItem.
<script type="text/javascript">
    function rgvReport_RowSelect(sender, eventArgs)
    {
        var rowindex = eventArgs.get_itemIndexHierarchical();
        document.getElementById("<%=txtrgvReportRowIndex.ClientID%>").value = eventArgs.get_itemIndexHierarchical();
        var TerGrid = $find("<%=rgvReport.ClientID %>");
        var gridRow = TerGrid.get_masterTableView().get_dataItems()[rowindex];
        var TerStatus = gridRow.getDataKeyValue("TerminationStatus");
        var radToolBar = $telerik.findControl(TerGrid.get_element(), "RTBTermination");
        if (TerStatus != "Termination Request")
        {
            radToolBar.get_items().getItem(0).set_enabled(false);
        }
        else
        {
            radToolBar.get_items().getItem(0).set_enabled(true);
        }
    }
</script>

Regards,
Daniel
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
answered on 23 Jul 2010, 12:00 PM
Hi Daniel

It Works fine.

Thank You Very Much.

-Anto
0
Neha
Top achievements
Rank 1
answered on 11 May 2011, 03:55 PM
Hi Daniel,

I am using RadGrid with CommandItemTemplate. I wanted to disable/eneable link button based on gridrow select.  How to find Linkbutton inside commandItem.

 I wrote below using this current forum referance but button inside commandItem.

<script type="text/javascript">
function OnRowSelecting(sender,eventArgs)
{
var TerGrid = $find('<%=radGridCompanyResult.ClientID %>');
  
var btn = $telerik.findControl(TerGrid.get_element(), "btnSend");
btn.disabled = 0;
}
</script>

Let me know what I am doing wrong in above code. var btn is always null for me. :(

Thanks,
Neha
0
Mohamed Salah Al-Din
Top achievements
Rank 1
answered on 25 May 2011, 10:06 AM
hi,

and how to disable it from server side in page load depend on some condisions  like permission (bool IsAllowed)
0
Daniel
Telerik team
answered on 25 May 2011, 10:57 AM
Hi guys,

@Neha: Regular ASP.NET controls does not have a client object so you have to use $telerik.findElement function to get their HTML representation.

@Mohamed: Try this one:
protected void Page_Load(object sender, EventArgs e)
{
    foreach(GridItem item in RadGrid1.MasterTableView.GetItems(GridItemType.CommandItem)
    {
        Control ctrl = item.FindControl("MyControl");
        if(ctrl != null)
            ctrl.Visible = false;
    }
}

Regards,
Daniel
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Answers by
Daniel
Telerik team
Anto (DLL Version : 2008.3.1314.35)
Top achievements
Rank 2
Neha
Top achievements
Rank 1
Mohamed Salah Al-Din
Top achievements
Rank 1
Share this question
or