Help with Ajax Code please

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
15 years ago
Hi,

I am newbie with this tool to development a new ecommerce site and i have some problem when i try to add ajax code.

When I try to create a new control using a repeater and update panel ajax control to paginate the product list , the explorer show me this error:

"Sys.WebForms.PageRequestManagerParserErrorException: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled.".

Could anyone say me why? or helpme about the ajax code in the nopcommerce tool?

Thanks in advance,
Pedro
15 years ago
Hi,

Can you post your code here.

Just to let you know, database level paging is implemented in the next release, so it save you some work if you wait.

Thanks,

Ben
15 years ago
Hi and Thank to answer me to fast.

I going to explain better, i create a new control named "paginar":

The html code to paginar:

------------------------------------------------------------------------------------------
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="btnPost" EventName="Click" />
        <asp:AsyncPostBackTrigger ControlID="btnPrev" EventName="Click" />
        <asp:AsyncPostBackTrigger ControlID="cmbPag" EventName="SelectedIndexChanged" />
        <asp:AsyncPostBackTrigger ControlID="Button1" EventName="Click" />
    </Triggers>
    <ContentTemplate>
        <table cellpadding="2" cellspacing="3" width="100%">
            <tr>
                <td colspan="3">
                    <asp:Repeater ID="rptrItems" runat="server">
                        <ItemTemplate>
                            <nopCommerce:ProductBox2 ID="ctrlProductBox"
                                Product='<%# Container.DataItem %>' runat="server" />
                        </ItemTemplate>
                    </asp:Repeater>      
                </td>
            </tr>
            <tr>
                <td align="right" width="100%">
                    <asp:Button ID="btnPrev" runat="server"  Text="&lt;&lt;"
                        onclick="btnPrev_Click"></asp:Button>
                </td>
                <td>
                    <asp:DropDownList ID="cmbPag" runat="server" Font-Size="X-Small"
                        Height="19px" onselectedindexchanged="cmbPag_SelectedIndexChanged"
                        Width="40px" AutoPostBack="True">
                    </asp:DropDownList>
                </td>
                <td>
                    <asp:Button ID="btnPost" runat="server" Text="&gt;&gt;" onclick="btnPost_Click"
                        Enabled="False" CausesValidation="False"></asp:Button>
                </td>
            </tr>
        </table>
    </ContentTemplate>
</asp:UpdatePanel>

---------------------------------------------------------------------------------------

Control "paginar" has the following controls:

repeater box -> contains the productbox2 control to show products.
button btnPost and  btnPrev -> is the button that allow the user move between the diferent page tho show product, every page show only 5 products.
DropDownList cmbPag-> Allow the user to select any page number.

The code to update the updatepanel in the control "paginar" is this:

------------------------------------------------------------------------------------------
public void btnPost_Click(object sender, EventArgs e)
        {
            cmbPag.SelectedIndex = cmbPag.SelectedIndex + 1;
            Session["Pag"] = cmbPag.SelectedIndex + 1;
            This.BindData()            

        }
------------------------------------------------------------------------------------------

and the BindData() code is:
-------------------------------------------------------------------------------------------
int pag = 1;
                if (Session["Pag"] != null)
                    pag = ((int)Session["Pag"]);
                if (pag <= 1)
                {
                    btnPrev.Enabled = false;
                    cmbPag.Enabled = false;
                }
                if (Session["Products"] != null)
                {
                    ProductCollection products = (ProductCollection)Session["Products"];
                    Session.Remove("Products");

                    int totalItems = products.Count;
                    int maxitemsporpag = SettingManager.GetSettingValueInteger("MaxItemPerPage.ProductBox2");
                    int cantpags = (int)Math.Round((double)(totalItems / maxitemsporpag), 0) + 1;
                    for (int j = 1; j <= cantpags; j++)
                    {
                        cmbPag.Items.Add(j.ToString());
                    }
                    
                    if (pag > 1)
                        cmbPag.SelectedIndex = pag - 1;
                    if (pag < cantpags)
                        btnPost.Enabled = true;

                    ProductCollection products2 = new ProductCollection();
                    int i = 1;
                    foreach (Product pr in products)
                    {
                        if (i > ((pag - 1) * maxitemsporpag) && i <= (pag * maxitemsporpag))
                            products2.Add(pr);
                        i = i + 1;
                    }
                    
                    cmbPag.Enabled = true;
                    rptrItems.DataSource = products2;
                    rptrItems.DataBind();
                }
                else
                {
                    cmbPag.Visible = false;
                    btnPost.Visible = false;
                    btnPrev.Visible = false;
                }
-------------------------------------------------------------------------------------------

When I push the post button, the explorer javascript debugger show the message written above in the first post.

Could you helpme please?

thanks in advance
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.