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

Server side event handling in radAjaxPanel not working

4 Answers 149 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Mansi
Top achievements
Rank 1
Mansi asked on 01 Aug 2011, 01:45 PM
I have a nested grid view in radAjaxPanel. In parent grid, there is one division, in which I am adding linkbuttons runtime on _ItemDatabound. I need to open picture files on click of the link button click.
Like, div in <itemTemplate>

<div id="divAddAttachment" runat="server">  </div>

And on server side, on _ItemDatabound event, I am adding link button and assigning click event of that.
lnkOtherattachment.Text = "link1" ;
 lnkOtherattachment.CommandArgument = userid;
 lnkOtherattachment.CommandName = strFilePath + ext;
 lnkOtherattachment.ID ="lnk" + Guid.NewGuid().ToString();
 lnkOtherattachment.Command += new CommandEventHandler(attach_Click);
 divAttachments.Controls.Add(lnkOtherattachment);


The whole grid is inside RadAjaxPanel. So, as i need to open image on click of the linkbutton,

function OnRequestStart(target, arguments) {             
     if (arguments.get_eventTarget().indexOf("lnk") > -1) {                
         arguments.set_enableAjax(false);
     }
 }


But it never calls the "attach_Click" event on click of the link button.
This works perfect outside the radGrid.
What's wrong with this code?

4 Answers, 1 is accepted

Sort by
0
Mansi
Top achievements
Rank 1
answered on 03 Aug 2011, 08:54 AM
Isn't there any solution for this? Can somebody reply ASAP?
0
Genti
Telerik team
answered on 03 Aug 2011, 12:32 PM
Hi Mansi,

The issue here is that you are plugging an event handler too late in the page life-cycle.
The ItemDataBound event of the RadGrid is fired just before PagePreRender. Which means that your handler won't get fired.
Consider plugging your handler early on in the page life cycle.
I.e ItemCreated would be a better option as it is fire just before PageLoad.


Give it a try and let me know.

Kind regards,
Genti
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
Mansi
Top achievements
Rank 1
answered on 06 Aug 2011, 06:53 AM
Hi.. Thanks for the reply.

Basically I have to bind the grid on each load, whether it is post back or not.
So it always loads the page and calls the _itemcreated event. I checked by binding the grid only when the page does not post back. In that case, it calls _itemcreated first, and then page_load. But with that code also, it is not calling the linkbutton click event.

.aspx page is like this..

<telerik:RadGrid ID="dtBook" AllowPaging="True" runat="server" PageSize="10" ShowHeader="false"
                 OnItemCreated="dtBook_ItemCreated" OnItemDataBound="dtBook_ItemDataBound" Width="100%"
                 Height="100%" OnPageIndexChanged="dtBook_PageIndexChanged">
                 <PagerStyle Mode="NumericPages" />
                 <MasterTableView TableLayout="Fixed">
                     <ItemTemplate>
                         <table>
                             <tr>
                                 <td class="gridtableborder">
                                     <asp:LinkButton ID="ll1" runat="server" Text="aaa"></asp:LinkButton>
                                 </td>
                             </tr>
                         </table>
                     </ItemTemplate>
                 </MasterTableView>
             </telerik:RadGrid>

Server side code:

protected void Page_Load(object sender, EventArgs e)
{
   BindGrid();
}
 
 protected void dtBook_ItemCreated(object sender, GridItemEventArgs e)
    {       
        if ((e.Item.ItemType == GridItemType.AlternatingItem | e.Item.ItemType == GridItemType.Item))
        {
            LinkButton lnkOtherattachment = (LinkButton)e.Item.FindControl("ll1");
            lnkOtherattachment.CommandArgument = "d7d21543-0faf";
            lnkOtherattachment.CommandName = "some path";
            lnkOtherattachment.ID = "lnkAttachment11" + Guid.NewGuid().ToString();
            lnkOtherattachment.Command += new CommandEventHandler(attach_Click);
        }
    }

void attach_Click(object sender, CommandEventArgs e)
{
}

Still it does not fire attach_click.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 06 Aug 2011, 12:15 PM
Hello,

You can achieve this thing by another way also which was shown in below.

<telerik:RadGrid ID="dtBook" AllowPaging="True" runat="server" PageSize="10" ShowHeader="false"
                 OnItemCreated="dtBook_ItemCreated" OnItemDataBound="dtBook_ItemDataBound" Width="100%"
                 Height="100%" OnPageIndexChanged="dtBook_PageIndexChanged">
                 <PagerStyle Mode="NumericPages" />
                 <MasterTableView TableLayout="Fixed" DataKeyNames="ID">
                     <ItemTemplate>
                         <table>
                             <tr>
                                 <td class="gridtableborder">
                                   <asp:LinkButton ID="btnlnk" runat="server" Text='<%# Eval("ID") %>' OnClick="btnlnk_Click"
                                ></asp:LinkButton>
                                 </td>
                             </tr>
                         </table>
                     </ItemTemplate>
                 </MasterTableView>
             </telerik:RadGrid>

protected void btnlnk_Click(object sender, EventArgs e)
    {
        LinkButton btnlnk = sender as LinkButton;
        GridDataItem item = btnlnk.NamingContainer as GridDataItem;
//       Image img = item.FindControl("YourImageControlID") as Image; // you get control like this
        int ID = Convert.ToInt32(item.GetDataKeyValue("ID"));
        // do your functinality
    }

Let me know if any concern.

Thanks,
Jayesh Goyani
Tags
Ajax
Asked by
Mansi
Top achievements
Rank 1
Answers by
Mansi
Top achievements
Rank 1
Genti
Telerik team
Jayesh Goyani
Top achievements
Rank 2
Share this question
or