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

Rad Ajax partial postback problem

4 Answers 170 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Edward
Top achievements
Rank 1
Edward asked on 12 Aug 2010, 05:56 PM

Hi

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="TestPartialPostback.aspx.vb"
    Inherits="Rentware.TestPartialPostback" %>
  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
     <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <div>
        <br />
        <telerik:RadFormDecorator ID="rfDecorator" runat="server" DecoratedControls="Buttons,Fieldset,RadioButtons,CheckBoxes" />
        <telerik:RadWindowManager runat="server" ID="radWindowMgr" />
        <telerik:RadAjaxManager ID="radAjaxMgr" runat="server">
            <ajaxsettings>
            <telerik:AjaxSetting AjaxControlID="cbTest">
                <UpdatedControls>                    
                    <telerik:AjaxUpdatedControl ControlID="testPanel" />
                </UpdatedControls>
            </telerik:AjaxSetting>
            </ajaxsettings>
        </telerik:RadAjaxManager>
        <h2>
            Account Management</h2>
        <telerik:RadTabStrip ID="RadTabsAccManage" runat="server" MultiPageID="RadMultiPageAccManage"
            SelectedIndex="0" Skin="WebBlue">
            <tabs>
            <telerik:RadTab Text="General">
            </telerik:RadTab>
            <telerik:RadTab Text="Contacts">
            </telerik:RadTab>
        </tabs>
        </telerik:RadTabStrip>
        <telerik:RadMultiPage ID="RadMultiPageAccManage" runat="server" SelectedIndex="0">
            <telerik:RadPageView ID="RadPageViewAccManageGeneral" runat="server">
                <telerik:RadGrid ID="RadGridAccManageMain" runat="server" GridLines="None" AutoGenerateColumns="False"
                    ShowStatusBar="true" AllowAutomaticDeletes="True" AllowAutomaticInserts="True"
                    AllowAutomaticUpdates="True" DataSourceID="SqlDataSource1">
                    <alternatingitemstyle cssclass="DisplayNone" />
                    <itemstyle cssclass="DisplayNone" />
                    <headerstyle cssclass="DisplayNone" />
                    <footerstyle cssclass="DisplayNone" />
                    <groupingsettings casesensitive="false" />
                    <mastertableview gridlines="None" datasourceid="SqlDataSource1" autogeneratecolumns="false"
                        datakeynames="RegionID">
                    <Columns>
                        <telerik:GridTemplateColumn ItemStyle-HorizontalAlign="Center" AllowFiltering="false">
                            <ItemTemplate>
                                   
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                    <EditFormSettings EditFormType="Template">
                        <FormTemplate>
                            <asp:CheckBox ID="cbTest" runat="server" Text="Enable" TextAlign="Left"
                                OnCheckedChanged="checkBoxCheckedChanaged" AutoPostBack="true" />
                            <asp:Panel ID="testPanel" runat="server" Enabled="false">
                                <fieldset>
                                    <legend>Add Or Edit Region:</legend>Region Description:
                                    <asp:TextBox runat="server" ID="txtText" Text='<%#Bind("RegionDescription") %>' />
                                </fieldset></asp:Panel>
                        </FormTemplate>
                    </EditFormSettings>
                </mastertableview>
                </telerik:RadGrid>
                <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
                    ProviderName="System.Data.SqlClient" SelectCommand="SELECT [RegionID], [RegionDescription] FROM [Region] WHERE ([RegionID] = @RegionID)"
                    runat="server">
                    <SelectParameters>
                        <asp:SessionParameter Name="RegionID" SessionField="regionId" Type="Int32" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </telerik:RadPageView>
            <telerik:RadPageView ID="RadPageViewAccManageContacts" runat="server">
            </telerik:RadPageView>
        </telerik:RadMultiPage>
    </div>
    </form>
</body>
</html>
Imports Telerik.Web.UI
Partial Public Class TestPartialPostback
    Inherits System.Web.UI.Page
    Dim regionId As Integer
    Dim commandName As String
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            regionId = Convert.ToInt32(Convert.ToString(Request.QueryString("regionId")))
            Session("regionId") = regionId
        End If
        commandName = IIf(Session("regionId").Equals(0), "PerformInsert", "Update").ToString()
    End Sub
    Private Sub RadGridAccManageMain_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGridAccManageMain.ItemCreated
        If TypeOf e.Item Is GridEditableItem AndAlso commandName = "Update" Then
            e.Item.Edit = True
        End If
    End Sub
  
    Protected Sub RadGridAccManageMain_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles RadGridAccManageMain.PreRender
        If Not Page.IsPostBack And commandName = "PerformInsert" Then
            RadGridAccManageMain.MasterTableView.IsItemInserted = True
            RadGridAccManageMain.Rebind()
            'RadGridAccManageMain.MasterTableView.InsertItem()
            RadGridAccManageMain.HeaderStyle.CssClass = "rgEditRow"
        End If
    End Sub
    Protected Sub checkBoxCheckedChanaged(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim thisCheckBox As CheckBox = CType(sender, CheckBox)
        Dim editItem As GridEditFormItem = DirectCast(thisCheckBox.NamingContainer, GridEditFormItem)
  
        CType(editItem.FindControl("testPanel"), Panel).Enabled = thisCheckBox.Checked
    End Sub
End Class

I’m using RadGrid for editing and inserting row in the place of using asp.net form view.  I’m passing the parameter to select the row for editing through query string.I’m assigning that query string to session variable in page load event and that session variable serves as select parameter in SQL Data source.If I get the required query string I’m putting RadGrid in Item Edit Mode and if not It will open the RadGrid in Item Insert mode.Inside Form Template I’ve a checkbox and asp.net panel that wraps all other contents of Form Template. I have an event to handle check box checked status changed.In that event I’m enabling and disabling the panel based on if the checkbox is checked or not.

 

I’ve RadAjaxManager in place with Ajax settings.  I’ve an AJAX setting in that RadAjaxManager with AjaxControlID as ID of the checkbox and AJAX updated control ID as the ID of the panel. So If I check or uncheck the checkbox In either Edit Mode or Insert Mode the panel should be enabled or disabled through AJAX partial post back.

 

Problem/Bug:

If the page loaded in insert mode for the first time and if I check the checkbox it is doing full post back and I can observe that clearly. (This is not expected behaviour).If I check the checkbox again it is doing partial ajaxified post back.But In Edit mode it is working fine (doing partial ajaxified post back) at all time.How I can fix this issue. For your reference I’ve attached the aspx and code behind file for you. It is stopping us from progressing further; your help would be very much appreciated.

4 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 18 Aug 2010, 08:57 AM
Hello Edward,

There are several issues with your AJAX settings and your current scenario. First, you specify server IDs of controls that are instantiated multiple times in a template. However, if you happen to initialize 2 edit forms at once, or an edit form and an insert form, which CheckBox and which Panel should get AJAX? One AJAX setting refers to one initiator and one updated control. Also, you can specify declarative AJAX settings only for controls that can be found either directly at the page level, or using FindControl() from the page. In effect, you are not advised to use declarative AJAX settings for control nested in naming containers or binding containers (that multiply them when databound). In your scenario, you have to programmatically add AJAX settings for these nested controls instead. Furthermore, you have to make sure your AJAX settings are added exactly once.

You can actually put an item in edit more, or put the master table in insert mode right on initial load where you check your query string parameters. I have attached a test page to demonstrate this. Check it out.

Kind 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
0
Veli
Telerik team
answered on 18 Aug 2010, 09:00 AM
Hello Edward,

Forgot to remove the declarative AJAX setting from the RadAjaxManager in the test page. Your RadAjaxSettings are all created in the code-behind, so you do not have any AJAX settings in the markup:

<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
</telerik:RadAjaxManager>

Greetings,
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
0
Amit
Top achievements
Rank 1
answered on 08 Feb 2014, 05:44 AM
i have same scanario and same problem/bug in my application i have widely used telerik control in my application so its not possible to change in design or adding ajax setting , so is there any other solution i can do with my application to avoid such problem . any one can help?
0
Maria Ilieva
Telerik team
answered on 12 Feb 2014, 11:28 AM
Hi Amit,

As this thread is rather old and since the last reply we have made several improvements in the RadAjax behavior it would be best if you could open s separate forum post/support ticket which presents the exact scenario you have and the problematic behavior you are facing. Thus we will be able to concentrate on your specific case and advise you further.

Regards,
Maria Ilieva
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Ajax
Asked by
Edward
Top achievements
Rank 1
Answers by
Veli
Telerik team
Amit
Top achievements
Rank 1
Maria Ilieva
Telerik team
Share this question
or