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

[Solved] Ajaxified control fails when using ListView ItemTemplate

1 Answer 112 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 1
Marco asked on 10 Aug 2009, 09:00 AM
Hi all,
I have a problem with a scenario I didn't find in all your demo, kb, and stuff.
I made a user control who work using radajaxmanagerproxy: it's a quite simple form for editing data, some textbox and a couple of combobox, with save and cancel button. If I use this control in an .aspx page, declaring a radajaxmanager, everything works fine.
But, if a create a page with a datalist, and declare the usercontrol inside the item template of the datalist, the ajax stuff don't work so well: the first time I try to use it, it's simply not ajaxified. From the second time on, the ajax stuff works.
I'll put the code of the page and the usercontrol: there are both cases (direct usercontrol declaration and datalist itemtemplate) on the same page. The user control is decalred directly for creating new item, and inside the datalist itemtemplate for editing.
Mainpage:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="ShowControl.aspx.vb" Inherits="test_ShowControl" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<%@ Register Src="../AttiviDetailsControl/Controparti.ascx" TagName="Controparti" 
    TagPrefix="uc1" %> 
<%@ Register Src="../AttiviDetailsControl/ContropartiItem.ascx" TagName="Contropartiitem" 
    TagPrefix="uc1" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
</head> 
<body> 
    <form id="form1" runat="server">  
    <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
    </telerik:RadScriptManager> 
    <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">          
    </telerik:RadAjaxManager> 
    <span>Create new item</span> 
    <uc1:Contropartiitem idAttivo="12" createNew="true" runat="server" ID="cpi1" /> 
    <br /> 
    <span>Editing</span> 
    <asp:Panel ID="editPanel" runat="server">  
        <asp:DataList ID="DataList1" runat="server" DataSourceID="LinqDataSource1" DataKeyField="IdControparte">  
            <ItemTemplate> 
                <uc1:Contropartiitem ID="ControPartiItem1" runat="server" createNew="false" idControparte='<%# Bind("IdControparte") %>' 
                    idAttivo='<%# Bind("IdAttivo") %>' cap='<%# Bind("CoCap") %>' idCompagnia='<%# Bind("IdCompagniaControparte") %>' 
                    idIspettorato='<%# Bind("IdIspettorato") %>' indirizzo='<%# Bind("CoIndirizzo") %>' 
                    localita='<%# Bind("CoLocalita") %>' marca='<%# Bind("Marca") %>' modello='<%# Bind("Modello") %>' 
                    nominativo='<%# Bind("NominativoControparte") %>' pr='<%# Bind("CoPR") %>' responsabileSx='<%# Bind("ResponsabileSiNo") %>' 
                    targa='<%# Bind("Targa") %>' telefoni='<%# Bind("CoTel") %>' /> 
            </ItemTemplate> 
        </asp:DataList> 
        <asp:LinqDataSource ID="LinqDataSource1" runat="server" EnableUpdate="true" ContextTypeName="ClaimsDataContext" 
            TableName="Contropartis">  
        </asp:LinqDataSource> 
    </asp:Panel> 
    </form> 
</body> 
</html> 
 

UserControl.aspx
<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ControPartiItem.ascx.vb" 
    Inherits="AttiviDetailsControl_ControPartiItem" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<telerik:RadAjaxManagerProxy ID="RadAjaxManagerProxy1" runat="server">  
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="btnSave">  
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="controparteItemPanel"   
                    LoadingPanelID="lp1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
        <telerik:AjaxSetting AjaxControlID="btnCancel">  
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="controparteItemPanel"   
                    LoadingPanelID="lp1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
        <telerik:AjaxSetting AjaxControlID="btnCreate">  
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="controparteItemPanel"   
                    LoadingPanelID="lp1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
        <telerik:AjaxSetting AjaxControlID="pVeicolo">  
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="pVeicolo" LoadingPanelID="lp1" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManagerProxy> 
 
<telerik:RadAjaxLoadingPanel ID="lp1" runat=server Skin="Sunset">  
</telerik:RadAjaxLoadingPanel> 
<asp:HiddenField ID="hfIdControparte" runat="server" /> 
<asp:HiddenField ID="hfIdAttivo" runat="server" /> 
<telerik:RadCodeBlock ID="rcb1" runat=server>  
<span><%=Now%></span>  
</telerik:RadCodeBlock> 
 
<asp:Panel ID="controparteItemPanel" runat="server">  
    <table> 
        <tr> 
            <td> 
                <label id="label1" runat="server" style="color: #990000">  
                    Veicolo</label> 
            </td> 
            <td> 
                <table width="100%">  
                    <tr> 
                        <td align="left">  
                            <label id="label2" runat="server" style="color: #990000">  
                                Controparte</label> 
                        </td> 
                        <td align="right">  
                            <label id="label3" runat="server">  
                                Responsabile del sinistro?</label> 
                            <telerik:RadComboBox ID="rcbResponsabileSx" runat="server" Width="50px">  
                                <Items> 
                                    <telerik:RadComboBoxItem Text="Si" Value="S" /> 
                                    <telerik:RadComboBoxItem Text="No" Value="N" /> 
                                </Items> 
                            </telerik:RadComboBox> 
                        </td> 
                    </tr> 
                </table> 
            </td> 
        </tr> 
        <tr> 
            <td> 
                <asp:Panel ID="pVeicolo" runat="server" BorderStyle="Solid" BorderColor="LightGray" 
                    BorderWidth="1px" Style="padding: 3px">  
                    <label id="label4" runat="server">  
                        Targa</label> 
                    &nbsp;&nbsp;&nbsp;&nbsp;  
                    <asp:TextBox ID="tbTarga" runat="server" BackColor="LightYellow" Width="80px"></asp:TextBox> 
                    <label id="label14" runat="server">  
                        Marca</label> 
                    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<asp:TextBox ID="tbMarca" runat="server"></asp:TextBox> 
                    <table> 
                        <tr> 
                            <td> 
                                <label id="label5" runat="server">  
                                    Modello</label> 
                            </td> 
                            <td> 
                                <asp:TextBox ID="tbModello" runat="server" Width="246px"></asp:TextBox> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td> 
                                <label id="label6" runat="server">  
                                    N° polizza</label> 
                            </td> 
                            <td> 
                                <asp:TextBox ID="tbPolizza" runat="server" Width="246px"></asp:TextBox> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td> 
                                <label id="label7" runat="server">  
                                    Compagnia</label> 
                            </td> 
                            <td> 
                                <telerik:RadComboBox ID="rcbCompagnia" runat="server" Width="250px" DataSourceID="ldsCompagnia" 
                                    DataTextField="RagioneSocialeCompagnia" DataValueField="IdCompagnia" Skin="Sunset" 
                                    AutoPostBack="true">  
                                </telerik:RadComboBox> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td> 
                                <label id="label8" runat="server">  
                                    Ispettorato</label> 
                            </td> 
                            <td> 
                                <telerik:RadComboBox ID="rcbIspettorato" runat="server" Width="250px" Skin="Sunset" 
                                    DataSourceID="ldsIspettorato" DataTextField="RagioneSocialeIspettorato" DataValueField="IdIspettorato">  
                                </telerik:RadComboBox> 
                            </td> 
                        </tr> 
                    </table> 
                </asp:Panel> 
            </td> 
            <td> 
                <asp:Panel ID="pControparte" runat="server" BorderStyle="Solid" BorderColor="LightGray" 
                    BorderWidth="1px" Height="140px">  
                    <table> 
                        <tr> 
                            <td> 
                                <label id="label9" runat="server">  
                                    Nominativo</label> 
                            </td> 
                            <td> 
                                <asp:TextBox ID="tbNominativo" runat="server" Width="246px"></asp:TextBox> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td> 
                                <label id="label10" runat="server">  
                                    Indirizzo</label> 
                            </td> 
                            <td> 
                                <asp:TextBox ID="tbIndirizzo" runat="server" Width="246px"></asp:TextBox> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td> 
                            </td> 
                            <td> 
                                <table style="border-collapse: collapse; padding: 0px; margin: 0px;">  
                                    <tr> 
                                        <td> 
                                            <label id="label12" runat="server">  
                                                C.A.P.</label> 
                                        </td> 
                                        <td> 
                                            <label id="label13" runat="server">  
                                                Località</label> 
                                        </td> 
                                        <td> 
                                            <label id="label15" runat="server">  
                                                PR</label> 
                                        </td> 
                                    </tr> 
                                    <tr> 
                                        <td> 
                                            <asp:TextBox ID="tbCAP" runat="server" Width="40px"></asp:TextBox> 
                                        </td> 
                                        <td> 
                                            <asp:TextBox ID="tbLocalita" runat="server" Width="170px"></asp:TextBox> 
                                        </td> 
                                        <td> 
                                            <asp:TextBox ID="tbPR" runat="server" Width="20px"></asp:TextBox> 
                                        </td> 
                                    </tr> 
                                </table> 
                            </td> 
                        </tr> 
                        <tr> 
                            <td> 
                                <label id="label11" runat="server">  
                                    Telefoni</label> 
                            </td> 
                            <td> 
                                <asp:TextBox ID="tbTelefoni" runat="server" Width="246px"></asp:TextBox> 
                            </td> 
                        </tr> 
                    </table> 
                </asp:Panel> 
            </td> 
        </tr> 
    </table> 
</asp:Panel> 
<asp:Panel ID="pEditButtons" runat=server > 
    <asp:Button ID="btnSave" runat="server" Text="Salva" /> 
    &nbsp;  
    <asp:Button ID="btnCancel" runat="server" Text="Annulla" /> 
</asp:Panel> 
<asp:Panel ID="pNewButtons" runat=server > 
    <asp:Button ID="btnCreate" runat="server" Text="Inserisci" /> 
</asp:Panel> 
 
<asp:LinqDataSource ID="ldsCompagnia" runat="server" ContextTypeName="ClaimsDataContext" 
    TableName="TabCompagnies">  
</asp:LinqDataSource> 
<asp:LinqDataSource ID="ldsIspettorato" runat="server" ContextTypeName="ClaimsDataContext" 
    TableName="TabIspettoratiCompagnies">  
</asp:LinqDataSource> 
 
usercontrol.vb
Imports System.Linq  
Imports System.Data.Linq  
Imports Telerik.Web.UI  
 
Partial Class AttiviDetailsControl_ControPartiItem  
    Inherits System.Web.UI.UserControl
#Region " property non visibili"  
 
    Public Property idControparte() As Integer 
        Get 
            If IsNumeric(hfIdControparte.Value) Then 
                Return hfIdControparte.Value  
            Else 
                Return -1  
            End If 
        End Get 
        Set(ByVal value As Integer)  
            hfIdControparte.Value = value  
        End Set 
    End Property 
 
    Public Property idAttivo() As Integer 
        Get 
            If IsNumeric(hfIdAttivo.Value) Then 
                Return hfIdAttivo.Value  
            Else 
                Return -1  
            End If 
        End Get 
        Set(ByVal value As Integer)  
            hfIdAttivo.Value = value  
        End Set 
    End Property 
 
    Public Property createNew() As Boolean 
        Get 
            Return ViewState("createNew")  
        End Get 
        Set(ByVal value As Boolean)  
            ViewState("createNew") = value  
        End Set 
    End Property
#End Region  
 
#Region " property sezione veicolo" 
 
    Public Property targa() As String 
        Get 
            Return tbTarga.Text  
        End Get 
        Set(ByVal value As String)  
            tbTarga.Text = value  
        End Set 
    End Property 
 
    Public Property marca() As String 
        Get 
            Return tbMarca.Text  
        End Get 
        Set(ByVal value As String)  
            tbMarca.Text = value  
        End Set 
    End Property 
 
    Public Property modello() As String 
        Get 
            Return tbModello.Text  
        End Get 
        Set(ByVal value As String)  
            tbModello.Text = value  
        End Set 
    End Property 
 
    Public Property polizza() As String 
        Get 
            Return tbPolizza.Text  
        End Get 
        Set(ByVal value As String)  
            tbPolizza.Text = value  
        End Set 
    End Property 
 
    Public Property idCompagnia() As Nullable(Of Integer)  
        Get 
            If IsNumeric(rcbCompagnia.SelectedValue) Then 
                Return rcbCompagnia.SelectedValue  
            Else 
                Return -1  
            End If 
        End Get 
        Set(ByVal value As Nullable(Of Integer))  
            If Not value Is Nothing Then 
                rcbCompagnia.SelectedValue = value  
            End If 
        End Set 
    End Property 
 
    Public Property idIspettorato() As Nullable(Of Integer)  
        Get 
            If IsNumeric(rcbIspettorato.SelectedValue) Then 
                Return rcbIspettorato.SelectedValue  
            Else 
                Return -1  
            End If 
        End Get 
        Set(ByVal value As Nullable(Of Integer))  
            If Not value Is Nothing Then 
                rcbIspettorato.SelectedValue = value  
            End If 
        End Set 
    End Property
#End Region  
 
#Region " property sezione controparte" 
 
    Public Property responsabileSx() As String 
        Get 
            Return rcbResponsabileSx.SelectedValue  
        End Get 
        Set(ByVal value As String)  
            rcbResponsabileSx.SelectedValue = value  
        End Set 
    End Property 
 
    Public Property nominativo() As String 
        Get 
            Return tbNominativo.Text  
        End Get 
        Set(ByVal value As String)  
            tbNominativo.Text = value  
        End Set 
    End Property 
 
    Public Property indirizzo() As String 
        Get 
            Return tbIndirizzo.Text  
        End Get 
        Set(ByVal value As String)  
            tbIndirizzo.Text = value  
        End Set 
    End Property 
 
    Public Property cap() As String 
        Get 
            Return tbCAP.Text  
        End Get 
        Set(ByVal value As String)  
            tbCAP.Text = value  
        End Set 
    End Property 
 
    Public Property pr() As String 
        Get 
            Return tbPR.Text  
        End Get 
        Set(ByVal value As String)  
            tbPR.Text = value  
        End Set 
    End Property 
 
    Public Property localita() As String 
        Get 
            Return tbLocalita.Text  
        End Get 
        Set(ByVal value As String)  
            tbLocalita.Text = value  
        End Set 
    End Property 
 
    Public Property telefoni() As String 
        Get 
            Return tbTelefoni.Text  
        End Get 
        Set(ByVal value As String)  
            tbTelefoni.Text = value  
        End Set 
    End Property
#End Region  
 
    Protected Sub ldsCompagnia_Selecting(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles ldsCompagnia.Selecting  
        Dim db As New ClaimsDataContext()  
        Dim sel = From comp In db.TabCompagnies _  
                  Where comp.Attivi = True _  
                  Or comp.IdCompagnia = idCompagnia _  
                  Order By comp.RagioneSocialeCompagnia _  
                  Select comp  
        e.Result = sel  
    End Sub 
 
    Protected Sub ldsIspettorato_Selecting(ByVal sender As ObjectByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles ldsIspettorato.Selecting  
        Dim db As New ClaimsDataContext()  
        Dim sel = From isp In db.TabIspettoratiCompagnies _  
                  Where isp.IdCompagnia = idCompagnia Or isp.IdIspettorato = idIspettorato _  
                  Order By isp.RagioneSocialeIspettorato _  
                  Select isp  
        e.Result = sel  
    End Sub 
 
    Protected Sub rcbCompagnia_SelectedIndexChanged(ByVal o As ObjectByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles rcbCompagnia.SelectedIndexChanged  
        rcbIspettorato.DataBind()  
    End Sub 
 
    Protected Sub btnSave_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnSave.Click  
        Try 
            'si recupera la controparte corrente  
            Dim db As New ClaimsDataContext()  
            Dim controparte As Controparti = (From c In db.Contropartis _  
                              Where c.IdControparte = idControparte _  
                              Select c).FirstOrDefault()  
            'vengono aggiornati i valori  
            controparte.CoCAP = cap  
            controparte.CoIndirizzo = indirizzo  
            controparte.CoLocalita = localita  
            controparte.CoPR = pr  
            controparte.CoTel = telefoni  
            controparte.IdCompagniaControparte = idCompagnia  
            controparte.IdIspettorato = idIspettorato  
            controparte.Marca = marca  
            controparte.Modello = modello  
            controparte.NominativoControparte = nominativo  
            controparte.NumeroPolizzaControparte = polizza  
            controparte.ResponsabileSiNo = responsabileSx  
            controparte.Targa = targa  
            'vengono rese persistenti (su db) le modifiche  
            db.SubmitChanges()  
            Alekso.Log.Logger.write("Salvataggio controparte id=" & idControparte & " avvenuto correttamente", _  
                                    Alekso.Log.Category.DATABASE, Alekso.Log.Severity.INFO, _  
                                    Session.getUser.nominativo)  
        Catch ex As Exception  
            Alekso.Log.Logger.write("Errore durante il salvataggio di una controparte, id=" & idControparte, _  
                                    Alekso.Log.Category.DATABASE, Alekso.Log.Severity.CRITICAL, _  
                                    Session.getUser.nominativo)  
        End Try 
 
    End Sub 
 
    Protected Sub btnCancel_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnCancel.Click  
        Try 
            'si recupera la controparte corrente  
            Dim db As New ClaimsDataContext()  
            Dim controparte As Controparti = (From c In db.Contropartis _  
                              Where c.IdControparte = idControparte _  
                              Select c).FirstOrDefault()  
            'vengono aggiornati i valori  
            cap = controparte.CoCAP  
            indirizzo = controparte.CoIndirizzo  
            localita = controparte.CoLocalita  
            pr = controparte.CoPR  
            telefoni = controparte.CoTel  
            idCompagnia = controparte.IdCompagniaControparte  
            idIspettorato = controparte.IdIspettorato  
            marca = controparte.Marca  
            modello = controparte.Modello  
            nominativo = controparte.NominativoControparte  
            polizza = controparte.NumeroPolizzaControparte  
            responsabileSx = controparte.ResponsabileSiNo  
            targa = controparte.Targa  
 
            Alekso.Log.Logger.write("Recuperata controparte id=" & idControparte & " a seguito di annullamento modifica", _  
                                    Alekso.Log.Category.DATABASE, Alekso.Log.Severity.DEBUG, _  
                                    Session.getUser.nominativo)  
        Catch ex As Exception  
            Alekso.Log.Logger.write("Errore durante il recupero di una controparte, id=" & idControparte, _  
                                    Alekso.Log.Category.DATABASE, Alekso.Log.Severity.ERROR, _  
                                    Session.getUser.nominativo)  
        End Try 
    End Sub 
 
    Protected Sub btnCreate_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnCreate.Click  
        Try 
            'creazione nuova controparte  
            Dim db As New ClaimsDataContext()  
            Dim controparte As New Controparti()  
            'valorizzazione campi  
            controparte.IdAttivo = idAttivo  
            controparte.CoCAP = cap  
            controparte.CoIndirizzo = indirizzo  
            controparte.CoLocalita = localita  
            controparte.CoPR = pr  
            controparte.CoTel = telefoni  
            controparte.IdCompagniaControparte = idCompagnia  
            controparte.IdIspettorato = idIspettorato  
            controparte.Marca = marca  
            controparte.Modello = modello  
            controparte.NominativoControparte = nominativo  
            controparte.NumeroPolizzaControparte = polizza  
            controparte.ResponsabileSiNo = responsabileSx  
            controparte.Targa = targa  
            'persistenza nuovo elemento  
            db.Contropartis.InsertOnSubmit(controparte)  
            db.SubmitChanges()  
            Alekso.Log.Logger.write("Salvataggio nuova controparte avvenuto correttamente", _  
                                    Alekso.Log.Category.DATABASE, Alekso.Log.Severity.INFO, _  
                                    Session.getUser.nominativo)  
        Catch ex As Exception  
            Alekso.Log.Logger.write("Errore durante il salvataggio di una nuova controparte", _  
                                    Alekso.Log.Category.DATABASE, Alekso.Log.Severity.CRITICAL, _  
                                    Session.getUser.nominativo)  
        End Try 
    End Sub 
 
    Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
        If Not IsPostBack Then 
            pEditButtons.Visible = Not createNew  
            pNewButtons.Visible = createNew  
 
        End If 
    End Sub 
 
End Class 
 


Moreover ther are some minor issues too.
If you try to use the "create new item" instance of the user control, you'll see that the ajax behaviour works fine but the rest of the page's layout is somehow... shaked for some moments. And this happen just the first time a postback occurs.

Not included in the sample attached, I have some problem also trying to put some ajax behaviour also on the .aspx page: if I declare in the radajaxmanager an ajaxsetting involving the single usercontrol instance to update the datalist panel (view following code snippet)
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">  
    <AjaxSettings> 
        <telerik:AjaxSetting AjaxControlID="cpi1">  
            <UpdatedControls> 
                <telerik:AjaxUpdatedControl ControlID="cpi1" LoadingPanelID="lp2" /> 
                <telerik:AjaxUpdatedControl ControlID="editPanel" LoadingPanelID="lp2" /> 
            </UpdatedControls> 
        </telerik:AjaxSetting> 
    </AjaxSettings> 
</telerik:RadAjaxManager> 
<telerik:RadAjaxLoadingPanel ID="lp2" runat=server Skin="Sunset">  
</telerik:RadAjaxLoadingPanel> 
 it simply disable ajax everywhere... and I have nomore ajax behaviour avalable.

Need some help please
Marco

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 12 Aug 2009, 12:01 PM
Hello Marco,

I reviewed the code, and it looks correct.
In order to further track the issues at hand, it will be best if you open a formal support ticket, and send us a small working project, demonstrating your logic, and the unwanted behavior.
We will review it locally, and get back to you with additional information.

Greetings,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Ajax
Asked by
Marco
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or