Mono Support Pager problem (Closed)

Viewed 16854 time(s), 5 post(s), 11/21/2011 6:16:38 PM - by Maxim
11/21/2011 6:16:38 PM
319 Reputation 30 Total posts

Hi!
I use standart MonoX Pager in my control, it's works fine. But when some controls at this same page contains a data(text in textbox), then after page switching, page goes to refresh with GET query parameters(no PostBack), and alldata get lost.

So please help me with one of ways:
1. Switch Off full page refresh of pager. Query parameters no necessary for me, simple PostBack. Can I do this?
2. Tell me how simple store and load data to page using MonoX features. :)

1
11/22/2011 8:01:41 AM
15993 Reputation 2214 Total posts

Hi Maxim,

MonoX has two types of pagers (two pager templates) as you may noticed, the SEO pager that you are probably using and the Postback pager. If you want your data to be preserved on the page you will probably need a postback pager and you can simple change the template for the pager to postback one and you will not be redirected to the same page and loose the data.

1. Switch Off full page refresh of pager. Query parameters no necessary for me, simple PostBack. Can I do this?
Yes, please let me know how do you use the pager so I can show you how to change the pager template. Postback pager template can be found in the following location: ~\App_Templates\Default\PagerTemplates\PostbackPager.ascx

2. Tell me how simple store and load data to page using MonoX features. :)
To store and load data on per page basis you can use simple ASP.NET ViewState mechanism (or if we are talking about the post back data stored in the controls such as TextBox, you just need to switch to postback pager and everything will work out of the box). If you choose to use the ViewState can you simple put your data into a ViewState and have no worries as MonoX has a WAO ViewState provider that will optimize the ViveState storage for you.

Let me know if you need anything else.

Regards

2
11/22/2011 9:07:05 AM
319 Reputation 30 Total posts

I've been used a simple MonoSoftware.Web.Pager. Now I try to use your variant, and have a problem:

Unable to cast object of type 'System.Web.UI.WebControls.Panel' to type 'MonoSoftware.Web.Pager.Pager'.

Description: An unhandled exception occurred during
the execution of the current web request. Please review the stack trace
for more information about the error and where it originated in the
code.
Exception Details: System.InvalidCastException:
Unable to cast object of type 'System.Web.UI.WebControls.Panel' to type
'MonoSoftware.Web.Pager.Pager'.
Source Error:
Line 52: {
Line 53: get { return uxPager.Pager.PageSize; }
Line 54: set { uxPager.Pager.PageSize = value; }
Line 55: }
Line 56:


Where uxPager is the pager.

protected global::MonoSoftware.MonoX.Controls.MonoXPagerTemplate uxPager;

Can you show me a little example of correct usage PostbackPager?

3
11/22/2011 3:18:19 PM
3016 Reputation 428 Total posts

Hi,

here is an example on how to use MonoX Postback pager with repeater:

Markup:

<asp:Repeater ID="repeater" runat="server">
    <HeaderTemplate>
        <table cellpadding="0" cellspacing="0" width="100%">
            <tr>
                <th>
                    First column
                </th>               
            </tr>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td>
                <%# ((YourEntity)(Container.DataItem)).CreatedOn %>
            </td>                         
        </tr>
        </ItemTemplate>
    <FooterTemplate>
        </table>
    </FooterTemplate>
</asp:Repeater>
     
<mono:Pager ID="pager" runat="server" AutoPaging="false" AllowCustomPaging="true" EnableViewState="true" PageSize="10" NumericButtonCount="5">
    <PagerTemplate>
        <mono:PagerTemplate ID="pagerTemplate" runat="server" />
    </PagerTemplate>
</mono:Pager>

Codebehind:

private void BindData()
 {
    int recordCount = 0;
    EntityCollection<YourEntity> yourEntities = YourRepository.GetInstance().GetYourEntities(pager.CurrentPageIndex + 1, pager.PageSize, out recordCount);
 
    PagerUtility.BindPager(pager, BindData, repeater, yourEntities, recordCount);
}

protected override void OnInit(EventArgs e)
{
    base.OnInit(e);
    pager.PageIndexChanged += new MonoSoftware.Web.Pager.PageChangedEventHandler(pager_PageIndexChanged);
 
}


protected override void OnLoad(EventArgs e)
{
    base.OnLoad(e);
 
    if (!IsPostBack)
    {
        BindData();
    }
    else
        pager.DataBind();
}

void pager_PageIndexChanged(object source, MonoSoftware.Web.Pager.PageChangedEventArgs e)
{
    pager.CurrentPageIndex = e.NewPageIndex;
    BindData();
}



Regards

4
11/23/2011 9:06:09 AM
319 Reputation 30 Total posts

Thanks for answer, first problem was in wrong ASPX declaration.
Second was function:
InitPagerTemplate(uxPager, PagerQueryString, PagerQueryStringSuffix);
Who dissalow to use PostBacks. After commenting it all works fine!

5
This is a demo site for MonoX. Please visit Mono Software for more info.