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

Rebind Command Item

3 Answers 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 19 Aug 2010, 07:38 PM
Hello,

I have a grid inside a user control with ajax. On the command item template, there is a linkbutton which initially has its visible property set to false. After a viewstate property is set, the grid's rebind method is called, which in turn causes the ItemCreated event to fire, at which time I find the linkbutton and set its visible property to true. The problem is, the button disappears again after a postback. I thought the problem was with the viewstate, but I changed the ItemCreated to always set it to visible. I found that when the postback occurs, the ItemCreated event fires but the button still disappears after being set to visible on the server. I also tried calling the rebind() method on every page_load but that causes problems with other postback commands (edit, delete). Is there a way to tell the command item to rebind?

Thank you
(Using Q2 2010 and IE7)

3 Answers, 1 is accepted

Sort by
0
Mira
Telerik team
answered on 20 Aug 2010, 02:39 PM
Hello Josh,

I tried to replicate the issue which you described, but to no avail.
Attached to this message, you will find the code which I used for testing.

Please, take a look at it and let me know if there are any differences at your end, which I may be leaving out.

Sincerely yours,
Mira
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
Josh
Top achievements
Rank 1
answered on 26 Aug 2010, 10:11 PM
Hi Mira,

Thanks for looking into this. The difference between my project and the test code is that the grid is inside a user control which is dynamically loaded into a RadPageView (which is itself dynamically created) on page_load.

I have created a workaround: I first changed the 'Visible="false"' property to 'style="display:none;"', and then did the following on the ItemCreated event:

protected void grid_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridCommandItem)
        {
            LinkButton addButton = (LinkButton)e.Item.FindControl("btnAdd");
            if (addButton != null && Edit)
            {
                RadAjaxManager.GetCurrent(Page).ResponseScripts.Add("setVisible('" + addButton.ClientID + "');");
            }
        }
    }

The javascript function then finds the button by its client ID and sets the display to 'block'. This method seems to be working and if there isn't a simple way to rebind the command item server-side then I'll stick with this.

Thank you,
Josh
0
Mira
Telerik team
answered on 31 Aug 2010, 04:06 PM
Hello Josh,

I am glad the issue is resolved.
Another way to implement the same functionality can found in the sample project attached to my previous message.

Sincerely yours,
Mira
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
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Mira
Telerik team
Josh
Top achievements
Rank 1
Share this question
or