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

[Solved] Force Postback not working with version 2009.2.826.20 radGrid

4 Answers 179 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul J
Top achievements
Rank 1
Paul J asked on 15 Oct 2009, 02:37 PM
I updated my telerik controls for one of my .net vb.net projects to  version 2009.2.826.20 and now it seems the force postback for a button within a grid template column within an ajaxified radGrid is no longer doing the regular postback. I was previously using a pretty old version, that involved including a dll like RadGrid.Net2.dll. Anyway, below is my code that previously worked with the older version. When I updated the controls, I also went through and re-added the ScriptManager (on Master Page) and the radAjaxManager and the radGrid to the page and reset its settings, after I brought in the new telerik controls DLL. With the new version, the controls within the grid that are supposed to run ajaxified are working fine. But now it seems when I click the button, it does an ajax postback, instead of the regular postback I am trying to force. If I add an EnableAjax="false" to the radAjaxManger, everything runs without error, but obviously now it no longer does ajax postbacks for other controls within the grid that I want to use Ajax.

 
<script type="text/javascript"
 
function realPostBack(eventTarget, eventArgument) 
__doPostBack(eventTarget, eventArgument); 
 
</script> 
 
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server"  DefaultLoadingPanelID="AjaxLoadingPanel1"
     <AjaxSettings> 
 
         <telerik:AjaxSetting AjaxControlID="rdgResults"
             <UpdatedControls> 
                 <telerik:AjaxUpdatedControl ControlID="rdgResults" LoadingPanelID="AjaxLoadingPanel1" />   
             </UpdatedControls> 
         </telerik:AjaxSetting> 
        </AjaxSettings>        
    </telerik:RadAjaxManager> 
     
<asp:panel id="pnlsearch" runat="server" DefaultButton="btnSearch"
... 
 <telerik:RadGrid ID="rdgResults" runat="server" AllowPaging="True" AllowSorting="True" EnableEmbeddedSkins="False" Skin="radGridSkin" Width="100%" EnableOutsideScripts="True" GridLines="None"
    <MasterTableView AutoGenerateColumns="False" AllowNaturalSort="False" NoMasterRecordsText="No Special Permission Requests Found." 
            PageSize="20"   DataKeyNames="RequestID" BorderColor="#B5E9AD"
... 
<Columns> 
... 
            <telerik:GridTemplateColumn UniqueName="tmpEditColumn"
             <HeaderTemplate> 
                            Edit 
                        </HeaderTemplate> 
                        <ItemTemplate> 
                            <div class="functionButtons"
                                <asp:Button runat="server" Text="" CssClass="btnEdit" ID="btnEdit"  CommandName="EditCustom"  /> 
                            </div> 
                        </ItemTemplate> 
            </telerik:GridTemplateColumn>                                    
         </Columns> 
 
       </MasterTableView> 
  
    
    </telerik:RadGrid> 
 
<asp:panel id="pnlReqEntry" runat="server"


Code to add the postback call to the button within the grid

   Protected Sub rdgResults_ItemCreated(ByVal sender As ObjectByVal e As Telerik.Web.UI.GridItemEventArgs) Handles rdgResults.ItemCreated 
        If (TypeOf e.Item Is GridDataItem) Then 
            Dim dataItem As GridDataItem = CType(e.Item, GridDataItem) 
            Dim button1 As Button = CType(dataItem("tmpEditColumn").FindControl("btnEdit"), Button) 
 
           
            button1.Attributes.Add("onclick"String.Format("realPostBack('{0}', '{1}'); return false;", button1.UniqueID, button1.CommandArgument)) 
             
        End If 
    End Sub 

and in my web.config:

    <compilation debug="true"
      <assemblies> 
        <add assembly="Telerik.Web.Design, Version=2009.2.826.20, Culture=neutral, PublicKeyToken=121FAE78165BA3D4" /> 
        <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" /> 
      </assemblies> 
    </compilation> 
<httpHandlers> 
      <add path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource, Telerik.Web.UI, Version=2009.2.826.20, Culture=neutral, PublicKeyToken=121fae78165ba3d4" verb="*" validate="false" /> 
    </httpHandlers> 
  </system.web> 
  <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    <handlers> 
      <add name="Telerik_Web_UI_WebResource_axd" verb="*" preCondition="integratedMode" path="Telerik.Web.UI.WebResource.axd" type="Telerik.Web.UI.WebResource" /> 
    </handlers> 


viewing the html source (had to set EnableAjax=false to even see this within the source html) for the button that should do a normal postback looks like:

  <input type="button" name="ctl00$ContentPlaceHolder1$rdgResults$ctl00$ctl04$btnEdit" value="" onclick="realPostBack('ctl00$ContentPlaceHolder1$rdgResults$ctl00$ctl04$btnEdit', ''); return false;WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$ContentPlaceHolder1$rdgResults$ctl00$ctl04$btnEdit&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))" id="ctl00_ContentPlaceHolder1_rdgResults_ctl00_ctl04_btnEdit" class="btnEdit" />


Is there something that has changed, regarding forcing postbacks with the newest version of the radGrid?

4 Answers, 1 is accepted

Sort by
0
Accepted
Sebastian
Telerik team
answered on 15 Oct 2009, 02:54 PM
Hello Paul J,

Indeed you are right and this is the expected behavior when RadGrid is ajaxified via RadAjaxManager (since it is built on top of the ASP.NET AJAX framework which transforms all __doPostBack(senderm eventArgs) calls on the page in async requests).

To force regular postback in this case, you need to disable the ajax from within the OnRequestStart handler of the ajax manager as demonstrated on this demo:
http://demos.telerik.com/aspnet-ajax/controls/examples/integration/raduploadinajaxifiedgrid/defaultcs.aspx?product=grid

For your case the function can be modified as shown below:

function conditionalPostback(sender, eventArgs)
  {
    if (eventArgs.get_eventTarget().indexOf("btnEdit") > -1)
    {
        eventArgs.set_enableAjax(false);
      }
    }
  }


Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Paul J
Top achievements
Rank 1
answered on 15 Oct 2009, 03:26 PM
Sebastian, thanks for the ultra quick response. Still having a little trouble though.

So, after adding the conditionalPostback function to a script block on the page, do I change the ItemCreated method of the radGrid to add the function conditionalPostback to the button's onclick event instead of using the realPostBack function as I was doing before?
i.e.

button1.Attributes.Add("onclick"String.Format("conditionalPostback('{0}', '{1}'); return false;", button1.UniqueID, button1.CommandArgument)) 

instead of:

button1.Attributes.Add("onclick"String.Format("realPostBack('{0}', '{1}'); return false;", button1.UniqueID, button1.CommandArgument)) 

if so, i must still be doing something wrong. it's giving a JavaScript error of:
Object doesn't suppose this property or method for:

function conditionalPostback(sender, eventArgs) 
  { 
    if (eventArgs.get_eventTarget().indexOf("btnEdit") > -1) //line 97 i believe
    { 
        eventArgs.set_enableAjax(false); 
      } 
  } 


in the ItemCreated method, what do I add the conditionalPostback  function to? Thanks...

0
Sebastian
Telerik team
answered on 15 Oct 2009, 03:36 PM
Hello Paul J,

It is not necessary to attach any javascript function to the onclick attribute of your button - you can safely remove it and handle the postback from the OnRequestStart handler of the manager. Please excuse me for not clarifying that in my first reply.

Best regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Paul J
Top achievements
Rank 1
answered on 15 Oct 2009, 03:39 PM
Sebastian, sorry, my fault, I figured it out as you were replying. I hadn't added it to the onRequestStart. I was impatient and was looking for an attribute simply titled: "OnRequestStart", but it's actually "ClientEvents-OnRequestStart".

So it was to add the following to the telerik RadAjaxManager tag:
ClientEvents-OnRequestStart="conditionalPostback" 



Thanks again! As always, telerik support is extremely helpful.
Tags
Grid
Asked by
Paul J
Top achievements
Rank 1
Answers by
Sebastian
Telerik team
Paul J
Top achievements
Rank 1
Share this question
or