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

Request value from button serverside ?

3 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Blok
Top achievements
Rank 1
David Blok asked on 17 Mar 2010, 03:56 PM
How can i request a value from a row serverside on a imagebutton click event ?

<telerik:GridTemplateColumn UniqueName="ArtID" DataField="ID" InitializeTemplatesFirst="false" ItemStyle-Width="20px" AllowFiltering="False"
                    <ItemTemplate> 
 
                        <a href="write_articletomodule.aspx?ArtID=<%#Eval("ID")%>&ModID=<%#request("ModID")%>&CatID=<%#request("CatID") %>&action=add"><img src="/admin/images/contextmenus/add.png" alt="Add" /></a> 
   
                     </ItemTemplate> 
                    <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" /> 
                </telerik:GridTemplateColumn>   

Now i have a html redirect to a page.
But i want to send these values to serverside on this page.

Anyone have an idea ?

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 18 Mar 2010, 08:17 AM

Hello David,

I achieved the same scenario by using an ImageButton inside template column and explicitly redirecting in ImageButton OnClick event. Here is the code that I tried.

ASPX:
<telerik:GridTemplateColumn UniqueName="ArtID" DataField="ID" InitializeTemplatesFirst="false" 
    ItemStyle-Width="20px" AllowFiltering="False"
    <ItemTemplate> 
        <asp:ImageButton ID="imgbtnNav" runat="server" ImageUrl="/admin/images/contextmenus/add.png" 
            OnClick="imgbtnNav_Click" /> 
    </ItemTemplate> 
    <ItemStyle HorizontalAlign="Left" VerticalAlign="Top" /> 
</telerik:GridTemplateColumn> 

C#:

protected
 void imgbtnNav_Click(object sender, ImageClickEventArgs e) 
        { 
            ImageButton btnNav = sender as ImageButton; 
            GridDataItem dataitem = (GridDataItem)btnNav.NamingContainer; 
            string ModID = dataitem["ModID"].Text; 
            string CatID = dataitem["CatID"].Text; 
            string ID = dataitem["ID"].Text; 
            Response.Redirect("write_articletomodule.aspx?ArtID=" + ID + "&ModID=" + request(ModID) + "&CatID=" + CatID+"&       action=add"); 
         
        } 

-Shinu
0
David Blok
Top achievements
Rank 1
answered on 18 Mar 2010, 11:00 AM
Thanks for the reply, I tried the code but it seems to fire but doesn't do anything.

I tried just to hide the button just to test, but it doesn't happen too.

Here is the code behind. Just trying if you click the button, it becomes invisible.

    Protected Sub imgbtnNav_Click(ByVal sender As ObjectByVal e As ImageClickEventArgs) 
 
        Dim btnNav As ImageButton = TryCast(sender, ImageButton) 
        Dim dataitem As GridDataItem = DirectCast(btnNav.NamingContainer, GridDataItem) 
 
        Dim ModID As String = dataitem("ModID").ToString 
        Dim CatID As String = dataitem("CatID").ToString 
        Dim ID As String = dataitem("ID").ToString 
 
        btnNav.Visible = False 
 
    End Sub 

0
Veli
Telerik team
answered on 19 Mar 2010, 01:56 PM
Hello David,

You can check with the VS debugger of your event handler is hit at all on postback.  If it is not, then the event handler is not properly attached. If it is hit and executes OK, but you see no visible change, then, if you are using AJAX, it might not be setup properly, preventing proper update of the content.

An alternative approach you can try is using RadGrid's ItemCommand event. The ImageButton inside the GridTemplateColumn can fire a custom command:

<telerik:GridTemplateColumn>
    <ItemTemplate>
        <asp:ImageButton ID="imgbtnNav" runat="server" CommandName="Custom"/>
    </ItemTemplate>
</telerik:GridTemplateColumn>

Once you have a custom command set up, the button's command bubbles to RadGrid's ItemCommand event:

Protected Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand
    If e.CommandName = "Custom" Then
        Dim item As Telerik.Web.UI.GridDataItem = CType(e.Item, Telerik.Web.UI.GridDataItem)
        Dim catId As String = item("CatID").Text
        'execute your custom logic here
    End If
End Sub

In this way, you have access to the grid data item from RadGrid's event.

Also  I noted in your VB code you are trying to get a data cell text using dataitem("ModID").ToString, while you need to access the Text property of the TableCell: dataitem("ModID").Text

Regards,
Veli
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
David Blok
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
David Blok
Top achievements
Rank 1
Veli
Telerik team
Share this question
or