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

Trigger Linkbutton automatically once grid is loaded

4 Answers 128 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Baal
Top achievements
Rank 1
Baal asked on 25 May 2011, 11:46 PM
I have a RadGrid. It contains multiple controls inside of it. One of them is a linkbutton whose clientClick triggers window.open. After the grid is loaded, I want to trigger the linkbutton's click if and only if the grid contains only one item.

I am defining the grid as follows:
<rad:RadGrid ID="rg" runat="server">
    <ClientSettings>
        <ClientEvents OnDataBound="rg_DataBound" />
    </ClientSettings>
    <MasterTableView PageSize="50" DataSourceID="ods" DataKeyNames="Id">
            <rad:GridTemplateColumn HeaderText="Name" SortExpression="a.Name">
                <ItemTemplate>
                    <asp:LinkButton ID="lblName" runat="server" />
                </ItemTemplate>
            </rad:GridTemplateColumn>
    </MasterTableView>
</rad:RadGrid>

In my codebehind, I am definining the ClientClick at the ItemCreated method.
var lb = (LinkButton)e.Item.FindControl("lbName");
lb.OnClientClick = "window.open('NewPage.aspx?id=" + obj.Id + "'); return false;";

I implemented the client grid databound as follows:
function rg_DataBound(sender, e) {
   var masterTable = $find('<%= rg.ClientID %>').get_masterTableView;
   var dataItems = masterTable.get_dataItems();
 
   if (masterTable.get_pageCount() == 1 && dataItems.get_count() == 1) {
      var lb = dataItems[0].findControl('lbName');
      lb.click();
   }
}

But this javascript method does not even get fired. Basically I have two questions at this time:
1. Am I in the right track?
2. Why is rg_DataBound not firing?

Thanks.

4 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 28 May 2011, 02:11 PM
Hello Baal,

Your logic seems correct. However, I would advise you to use the client OnGridCreated event since it is fired every time the page loads, while the OnDataBound event is fired only when using client side data-binding.

Regards,
Tsvetina
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.

0
Baal
Top achievements
Rank 1
answered on 02 Jun 2011, 07:59 PM
Hello Tsvetina,

OnGridCreated works. I had a few implementation issues, which I fixed. Here's what the function looks like:
function rg_GridCreated(sender, e) {
    var masterTable = sender.get_masterTableView();
    var dataItems = masterTable.get_dataItems();
  
    if (masterTable.get_pageCount() == 1 && dataItems.length == 1) {
        var lb = dataItems[0].findControl('lbName');
        lb.click();
    }
}

Everything works now, except for lb, which is always null. I am using Telerik.Web.UI 2010.2.173.35.

Thanks.
0
Tsvetina
Telerik team
answered on 06 Jun 2011, 03:22 PM
Hello Baal,

In the mark up of your previous post the control was named lblName while in the current javascript you try to address it using lbName. Can you confirm that if this is the cause of the issue?

Regards,
Tsvetina
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.

0
Baal
Top achievements
Rank 1
answered on 07 Jun 2011, 03:19 PM
lblName was a typo. It should have been lbName.

The problem is findControl. I changed findControl to findElement and it worked.

Thanks.
Tags
Grid
Asked by
Baal
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Baal
Top achievements
Rank 1
Share this question
or