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

Disabling ajax for two different imagebutton controls in a GridTemplateColumn in order to do a regular post back.

1 Answer 36 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 17 Oct 2011, 05:55 PM
In an ajaxified RadGrid, I want two buttons to cause a post back (bypass Ajax) and execute some back-end code. Here's what I have so far...

Buttons (just showing one for simplicity):
<telerik:GridTemplateColumn HeaderText="Actions">  
    <ItemTemplate>
        <asp:ImageButton ID="btnEdit" runat="server" OnClientClick="realPostBack();"  ImageUrl="~/images/icon_edit.png" style="display: inline-block" ToolTip="Edit" CommandName="fbEdit"  />
    </ItemTemplate>
</telerik:GridTemplateColumn>

Javascript function I'm using to disable the postback:
<script type="text/javascript">
  function realPostBack(eventTarget, eventArgument) {
    $find("<%= RadAjaxPanel1.ClientID %>").__doPostBack(eventTarget, eventArgument);
  }
</script>

Code-behind I want to execute:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
 {
   if (e.CommandName == "fbEdit")
      {
        //grab variables from row's cells
       string userID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["UserID"];
       string userName= e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["UserName"];
       string userEmail = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["UserEmail"];
 
       //DO SOME PROCESSING STUFF
 
      }
   if(e.CommandName == "fbDelete")
    {
       //delete record
     }
 }

So the post back does indeed occur, but my code never fires. I'm guessing it's because the event is tied to the grid and not to buttons im "un-ajaxifying", but I went this way because I NEED to capture the values of some of the cells in the row that the button was clicked.

Maybe I can rework this to use the buttons onClick Event, but I would still need to capture those values.

Can anyone help?

1 Answer, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 17 Oct 2011, 06:07 PM
Hello,

<script type="text/javascript">
        function onRequestStart(sender, args)
        {
            if (args.get_eventTarget().indexOf("btnEdit") >= 0)
            {
                args.set_enableAjax(false);
            }
        }
    </script>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
        <ClientEvents OnRequestStart="onRequestStart" />
        <AjaxSettings>
            <telerik:AjaxSetting AjaxControlID="RadGrid1">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                </UpdatedControls>
            </telerik:AjaxSetting>
        </AjaxSettings>
    </telerik:RadAjaxManager>
 
<telerik:RadGrid ID="RadGrid1" >
      ..............
..............
<telerik:GridTemplateColumn HeaderText="Actions"
    <ItemTemplate>
        <asp:ImageButton ID="btnEdit" runat="server" OnClientClick="realPostBack();"  ImageUrl="~/images/icon_edit.png" style="display: inline-block" ToolTip="Edit" CommandName="fbEdit"  />
    </ItemTemplate>
</telerik:GridTemplateColumn>
 
...........
..............
    </telerik:RadGrid>


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Greg
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or