开发者

Disable ajax for an imagebutton control inside a GridTemplateColumn of an ajaxified RadGrid

In an ajaxified RadGrid I want two buttons to cause a postback (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);
  }

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 c开发者_JS百科an rework this to use the buttons onClick Event, but I would still need to capture those values.

Can anyone help?


From the look of things you are attempting to execute code in the OnItemCommand event of the RadGrid, but it seems like you might be making things a bit over-complicated. Why not use a GridButtonColumn, set the ButtonType to ImageButton and then set the same CommandName as you do above? As long as you're subscribing to the OnItemCommand event this should trigger everything to get called and your conditional check for e.CommandName == "fbEdit" should be hit as well.

For an example of how to use this RadGrid specific column (in a similar manner) you can check out this demo.


In you need to add bellow code in PageLoad Event.

 if (!IsPostBack)
 {
     RadGridName.Rebind();
 }

thats it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜