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

Loading ascx templates and ajax manager problem

4 Answers 115 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Kieran Southern
Top achievements
Rank 1
Kieran Southern asked on 03 Nov 2008, 01:40 PM
Hi,

I have a formview that is loading an ascx template dynamically:

 <data:MultiFormView ID="FormView1" DataKeyNames="TransactionId" runat="server" DataSourceID="LoyaltyTransactionDataSource">
       
            <EditItemTemplatePaths>
                <data:TemplatePath Path="~/UserControls/LoyaltyTransactionFields.ascx" />
            </EditItemTemplatePaths>
       
            <InsertItemTemplatePaths>
                <data:TemplatePath Path="~/UserControls/LoyaltyTransactionFields.ascx" />
            </InsertItemTemplatePaths>
 

        </data:MultiFormView>

I'm trying to add an ajax manager to the page to pair up some of the controls in the ascx page. I think I need to do this programatically due to the controls being in the ascx page.

My ascx looks like this:

<%@ Control Language="C#" ClassName="LoyaltyTransactionFields" AutoEventWireup="true" CodeFile="LoyaltyTransactionFields.ascx.cs" Inherits="UserControls_LoyaltyTransactionFields" %>
<%@ Register Assembly="RadInput.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>
<%@ Register Assembly="RadCalendar.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>


<asp:FormView ID="FormView1" runat="server">
    <ItemTemplate>
        <table border="0" cellpadding="3" cellspacing="1">
            <tr>
                <td class="literal">Transaction Date:</td>
                <td>

                           
                    <rad:RadDatePicker SelectedDate='<%# Bind("TransactionDate") %>' ID="dataTransactionDate" runat="server" Culture="English (United Kingdom)" Skin="Default2006">
                        <Calendar Skin="Default2006" ShowRowHeaders="False">
                        </Calendar>
                        <DateInput Skin="Default2006" Font-Size="Larger">
                        </DateInput>
                    </rad:RadDatePicker>
                    <asp:RequiredFieldValidator ID="ReqVal_dataTransactionDate" runat="server" Display="Dynamic" ControlToValidate="dataTransactionDate" ErrorMessage="Required"></asp:RequiredFieldValidator>

                </td>
            </tr>               
            <tr>
                <td class="literal">Transaction Value:</td>
                <td>
                    <asp:TextBox runat="server" ID="dataTransactionValue" Text='<%# Bind("TransactionValue") %>'></asp:TextBox><asp:RequiredFieldValidator ID="ReqVal_dataTransactionValue" runat="server" Display="Dynamic" ControlToValidate="dataTransactionValue" ErrorMessage="Required"></asp:RequiredFieldValidator><asp:RegularExpressionValidator ID="RegExVal_dataTransactionValue"  runat="server" ControlToValidate="dataTransactionValue" Display="Dynamic" ValidationExpression="^[-]?(\d{1,9})(?:[.,]\d{1,4})?$" ErrorMessage="Invalid Value" />
                    </td>
            </tr>               
               
            <tr>
                <td class="literal">Description:</td>
                <td>
                    <asp:TextBox Width="300px" runat="server" ID="dataDescription" Text='<%# Bind("Description") %>' MaxLength="100"></asp:TextBox>
                </td>
            </tr>               
            <tr>
                <td class="literal">Archived:</td>
                <td>
                    <asp:RadioButtonList runat="server" ID="dataArchived" SelectedValue='<%# Bind("Archived") %>' RepeatDirection="Horizontal"><asp:ListItem Value="True" Text="Yes"></asp:ListItem><asp:ListItem Value="False" Text="No" Selected="True"></asp:ListItem></asp:RadioButtonList>
                </td>
            </tr>               
            <tr>
                <td class="literal">Card Id:</td>
                <td>
                    <data:EntityDropDownList AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" runat="server" ID="dataCardId" DataSourceID="CardIdLoyaltyCardDataSource" DataTextField="CardId" DataValueField="CardId" SelectedValue='<%# Bind("CardId") %>' AppendNullItem="true" Required="true" NullItemText="< Please Choose ...>" ErrorText="Required" />
                    <data:LoyaltyCardDataSource ID="CardIdLoyaltyCardDataSource" runat="server" SelectMethod="GetAll"  />
                </td>
            </tr>               
            <tr>
                <td class="literal">Customer Id:</td>
                <td>
                    <data:EntityDropDownList ReadOnly="true" runat="server" ID="dataCustomerId" DataSourceID="CustomerIdLoyaltyCustomerProfileDataSource" DataTextField="CustomerName" DataValueField="CustomerId" SelectedValue='<%# Bind("CustomerId") %>' AppendNullItem="true" Required="true" NullItemText="< Please Choose ...>" ErrorText="Required" />
                    <data:LoyaltyCustomerProfileDataSource ID="CustomerIdLoyaltyCustomerProfileDataSource" runat="server" SelectMethod="GetAll"  />
                </td>
            </tr>               
            <tr>
                <td class="literal">User Profile Id:</td>
                <td>
                    <data:EntityDropDownList ReadOnly="true" runat="server" ID="dataUserProfileId" DataSourceID="UserProfileIdLoyaltyUserProfileDataSource" DataTextField="Surname" DataValueField="UserProfileId" SelectedValue='<%# Bind("UserProfileId") %>' AppendNullItem="true" Required="true" NullItemText="< Please Choose ...>" ErrorText="Required" />
                    <data:LoyaltyUserProfileDataSource ID="UserProfileIdLoyaltyUserProfileDataSource" runat="server" SelectMethod="GetAll"  />
                </td>
            </tr>               
           
        </table>

    </ItemTemplate>
</asp:FormView>

I've added an ajax manager the containing page and then in the page_load:

        EntityDropDownList DataCardId = (EntityDropDownList)FormView1.FindControl("dataCardId");
        EntityDropDownList DataUserProfileId = (EntityDropDownList)FormView1.FindControl("dataUserProfileId");
        RadAjaxManager1.AjaxSettings.AddAjaxSetting(DataCardId, DataUserProfileId, null);


This compiles but when I run the app and choose from one of the dropdownlists I get the error:

Validation of viewstate MAC failed. If this application is hosted by a Web Farm or cluster, ensure that <machineKey> configuration specifies the same validationKey and validation algorithm. AutoGenerate cannot be used in a cluster.

Any suggestions greatly appreciated.

4 Answers, 1 is accepted

Sort by
0
Nikolay Rusev
Telerik team
answered on 05 Nov 2008, 04:23 PM

Hello Kieran,

Can you please try using regular MS UpdatePanel to see whether the same issue still arise? As I understand this is a runtime error. One possible reason for it is if something forces the page to postback before its fully loaded.

If the problem appears only when RadAjaxManager is present on the page, I suggest you open a formal support ticket and send us a simple runnable version of your project which replicates the problem. Thus we'll be able to help you further.

Best regards,
Nikolay
the Telerik team


Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Kieran Southern
Top achievements
Rank 1
answered on 17 Nov 2008, 12:19 PM
Hi,

I'm actually not using .net 3.5 so I dont have the updatepanel available to me.

The RadAjaxManager is actually running within the nettiers code on a master page, I wondered if a bit more information would help to identify the problem. Should this work okay?

Thanks again
0
Kieran Southern
Top achievements
Rank 1
answered on 17 Nov 2008, 12:22 PM
Actually I just spotted this:

http://community.codesmithtools.com/forums/p/7035/26799.aspx

Seems like others have had the same issue but unfortunately no fix on that post!
0
Nikolay Rusev
Telerik team
answered on 20 Nov 2008, 08:34 AM
Hello Kieran,

UpdatePanel control is hosted in System.Web.UI namespace of System.Web.Extenstions.dll assembly and it is installed with .Net framework 3.5. You can find more information about UpdatePanel and how it works here.

What RadAjaxManager does is to create an UpdatePanel around the controls which are in its UpdatedControls collection. Thus as I suggest you in my previous post, you can try replacing RadAjaxManager with an UpdatePanel and see if the same behavior will be observed.

Have in mind that you must set UpdatePanel.UpdateMode to Conditional.

Best wishes,
Nikolay
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Ajax
Asked by
Kieran Southern
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Kieran Southern
Top achievements
Rank 1
Share this question
or