Click here to Skip to main content
11,487,401 members (70,404 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#3.0 ASP.NET Ajax Cache , +
I have a data list control which is placed inside a content place holder.
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
    <asp:ScriptManager ID="MainScriptManager" runat="server" />
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <asp:DataList ID="dlProdocut" runat="server" RepeatColumns="3" EditItemIndex="-1"
                RepeatDirection="Horizontal" OnItemDataBound="dlProdocut_ItemDataBound">
                <ItemTemplate>
                    <asp:Table ID="Table1" runat="server" border="0" CellSpacing="0" CellPadding="0">
                        <asp:TableRow>
                            <asp:TableCell Height="10" HorizontalAlign="Center" VerticalAlign="Top">
 
                            </asp:TableCell>
                        </asp:TableRow>
                        <%--Image--%>
                        <asp:TableRow>
                            <asp:TableCell Height="150" Width="7" HorizontalAlign="left" VerticalAlign="top">
                                <asp:HyperLink ID="hyrProductImg" runat="server">
                              <img alt='<%# DataBinder.Eval(Container.DataItem,"Title")%>' src="../images/<%# DataBinder.Eval(Container.DataItem,"SmallImage") %>" border="0" width="226" height="166" />
                                </asp:HyperLink>
                            </asp:TableCell>
                            <asp:TableCell Width="5">&nbsp;&nbsp;</asp:TableCell>
                        </asp:TableRow>
                        <%--Title--%>
                        <asp:TableRow>
                            <asp:TableCell Height="45" Width="7" CssClass="product-name" HorizontalAlign="Center"
                                VerticalAlign="Top">
                            <strong>&nbsp;<%# DataBinder.Eval(Container.DataItem, "Title")%></strong>
                            </asp:TableCell>
                        </asp:TableRow>
                        <%--ShortDescription--%>
                        <asp:TableRow>
                            <asp:TableCell Width="7" HorizontalAlign="Justify" VerticalAlign="Top" CssClass="testimonial-text">
                                <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ShortDescription")%>'></asp:Label>
                            </asp:TableCell>
                        </asp:TableRow>
                        <%--Read More--%>
                        <asp:TableRow>
                            <asp:TableCell HorizontalAlign="Left">
                                <asp:HyperLink ID="lnkProductDetails" CssClass="read-more" runat="server">Read More &rarr;</asp:HyperLink>
                            </asp:TableCell>
                        </asp:TableRow>
                        <asp:TableRow>
                            <asp:TableCell Height="60" HorizontalAlign="Justify" VerticalAlign="Top" CssClass="testimonial-text">
 
                            </asp:TableCell>
                        </asp:TableRow>
                    </asp:Table>
                </ItemTemplate>
            </asp:DataList>
        </ContentTemplate>
        <Triggers>
            <asp:AsyncPostBackTrigger ControlID="dlProdocut" />
            <asp:AsyncPostBackTrigger ControlID="btnNext" />
        </Triggers>
    </asp:UpdatePanel>
    <asp:Label ID="lblPage" runat="server" Text="" />
    <asp:Button ID="btnPrevious" runat="server" Text="&lt;&lt;" />
    <asp:Button ID="btnNext" runat="server" Text="&gt;&gt;" OnClick="btnNext_Click" />
    <asp:Panel ID="BottomPager_Panel" runat="server">
    </asp:Panel>
</asp:Content>

On click of next button i am doing paging on the control and navigating to the next page.
On page load i am doing this
if (!IsPostBack)
        {
            pageCount = 1;
            PageNo = 1;
            startPage = 6 * (PageNo - 1) + 1;
             lastPage = startPage + 5;
             bindDataList();
        }

This is my code for bindDataList
public void bindDataList()
    {
        
        string source = ConfigurationManager.ConnectionStrings["Cad-B"].ToString();
        SqlConnection con = new SqlConnection(source);
        SqlCommand cmd = new SqlCommand("sp_GetProductPagingByMenuId", con);
        //cmd.CommandType = CommandType.StoredProcedure;
        //cmd.CommandText = "sp_GetProductPagingByMenuId";
        con.Open();
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@startPage", startPage);
        cmd.Parameters.Add("@lastPage", lastPage);
        SqlDataReader dr =    cmd.ExecuteReader();
        DataTable dt = new DataTable();
        dt.Load(dr);
        
        dlProdocut.DataSource = dt;
        dlProdocut.DataBind();
    }


On click of next button i have written the following code
protected void btnNext_Click(object sender, EventArgs e)
    {
        dlProdocut.DataSource = null;
        dlProdocut.DataBind();
        pageCount++;
        PageNo = pageCount;
        startPage = 6 * (PageNo - 1) + 1;
        lastPage = startPage + 5;
        bindDataList();
    }

Problem i am facing is that it every time shows me the same content that is loaded the first time on the page. When i debug the code i can see that the data list is loaded with the new records but it is not reflected on the page i tried removing caching but it dint help. The moment i removed the next button from the trigger section it is giving me the proper record but the complete page is getting post back which i dont want. This is the removed code
<asp:AsyncPostBackTrigger ControlID="btnNext" />
Please help i am stuck with this since long. I am new to this technology. Thanks in advance.
Posted 21-Jul-11 3:55am
Edited 21-Jul-11 17:57pm
v2
Comments
Christian Graus at 21-Jul-11 19:30pm
   
why are people who are 'new to this technology;' trying to do complicated things, hoping it all magically works, in situations that sure look like paid work ?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
Your code you'd posted is incomplete.
Where did you initialized the value of the following:
1. pageCount
2. PageNo
3. startPage
4. lastPage
If I am not mistaken above variable was declared as public right?

If I am not mistaken your application has a Master Page.
If so, then clicking button(s) rather executing an event the system
will postback to Master Page then to present page, resulting the
value of you four above variable to initialized.

Think something to handle the above variables value not to initialized.

You may use.
Session State or View State to handle this situation...
Example:

Session["startPage"] = startPage.ToString();
or
VieState["startPage"] = startPage.ToString();

Then on retrieving from page event..

Example:
int startPage = Convert.ToInt(Session["startPage"])
or
int startPage = Convert.ToInt(ViewState["startPage"])

Session State Expires... Remember...

You may search the differences between the two usage and decide which is best...

Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Regards,

Algem
  Permalink  
v4
Comments
ubaidh sayed at 22-Jul-11 6:57am
   
Hello Algem,
Thanks for replying. Yes you are right my page is using a master page and the variables you mentioned are public static and first time they are called and initialized in the "is postback" section of page load" i.e
if (!IsPostBack)
{
pageCount = 1;
PageNo = 1;
startPage = 6 * (PageNo - 1) + 1;
lastPage = startPage + 5;
bindDataList();
}

and later the value changes on click of the next button
i.e
protected void btnNext_Click(object sender, EventArgs e)
{
dlProdocut.DataSource = null;
dlProdocut.DataBind();
pageCount++;
PageNo = pageCount;
startPage = 6 * (PageNo - 1) + 1;
lastPage = startPage + 5;
bindDataList();
}

The problem i think is that the trigger
<asp:AsyncPostBackTrigger ControlID="btnNext" />
is not updating the update panel.
I tried updatepanel1.update() but dint work. The problem is that the update panel is not getting updated.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Hi,

Try to modified your code as:
 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
into
 <asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMod="Conditional">

then in your click event:

   UpdatePanel1.Update();


or if not work the try this one:

 <asp:UpdatePanel ID="UpdatePanel1" runat="server">
 <Triggers>
 <asp:AsyncPostBackTrigger ControlID="btnNext" EventName="Click" />
 &lt;asp:AsyncPostBackTrigger ControlID="dlProdocut" EventName="Click" /&gt;
 
  </Triggers>
  <ContentTemplate>
....
....

Hope this could help.

Regards,

Algem
  Permalink  
Comments
ubaidh sayed at 26-Jul-11 1:38am
   
Hi Al Moje,
Adding this part in code
<asp:AsyncPostBackTrigger ControlID="dlProdocut" EventName="Click"/> gives me an error.
"Could not find an event named 'Click' on associated control 'dlProdocut' for the trigger in UpdatePanel 'UpdatePanel1'."

Adding this
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMod="Conditional">

is not working either.
Al Moje at 26-Jul-11 2:29am
   
Hi,

I'd notice that the buttons:
<asp:Button ID="btnPrevious" runat="server" Text="<<" />
<asp:Button ID="btnNext" runat="server" Text=">>" OnClick="btnNext_Click" />

you were triggered is outside you update panel
try to place it inside you update panel...
ubaidh sayed at 30-Jul-11 2:08am
   
I have tried that but nothing seems to work.
Here is my updated code.
<asp:Content ID="Content3" ContentPlaceHolderID="MainContent" runat="Server">
<asp:ScriptManager ID="MainScriptManager" runat="server" EnablePartialRendering="true" />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional">

<asp:DataList ID="dlProdocut" runat="server" RepeatColumns="3" RepeatDirection="Horizontal"
BorderColor="Black">

<asp:Table ID="Table1" runat="server" border="0" CellSpacing="0" CellPadding="0">
<asp:TableRow>
<asp:TableCell Height="10" HorizontalAlign="Center" VerticalAlign="Top">



<%--Image--%>
<asp:TableRow>
<asp:TableCell Height="150" Width="7" HorizontalAlign="left" VerticalAlign="top">
<asp:HyperLink ID="hyrProductImg" runat="server">
<img alt='<%# DataBinder.Eval(Container.DataItem,"Title")%>' src="../images/<%# DataBinder.Eval(Container.DataItem,"SmallImage") %>" border="0" width="226" height="166" />


<asp:TableCell Width="5">

<%--Title--%>
<asp:TableRow>
<asp:TableCell Height="45" Width="7" CssClass="product-name" HorizontalAlign="Center"
VerticalAlign="Top">
<%# DataBinder.Eval(Container.DataItem, "Title")%>


<%--ShortDescription--%>
<asp:TableRow>
<asp:TableCell Width="7" HorizontalAlign="Justify" VerticalAlign="Top" CssClass="testimonial-text">
<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container.DataItem,"ShortDescription")%>'>


<%--Read More--%>
<asp:TableRow>
<asp:TableCell HorizontalAlign="Left">
<asp:HyperLink ID="lnkProductDetails" CssClass="read-more" runat="server">Read More →


<asp:TableRow>
<asp:TableCell Height="60" HorizontalAlign="Justify" VerticalAlign="Top" CssClass="testimonial-text">






<asp:Label ID="lblPage" runat="server" Text="" />
<asp:Button ID="Button1" runat="server" Text="<<" />
<asp:Button ID="btnNext" runat="server" Text=">>" OnClick="btnNext_Click" />

<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnNext" EventName="Click" />
<asp:AsyncPostBackTrigger ControlID="dlProdocut" />
</Triggers>

<asp:Panel ID="BottomPager_Panel" runat="server">

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 9,063
1 OriginalGriff 8,287
2 Sascha Lefèvre 3,334
3 Maciej Los 2,946
4 Richard Deeming 2,370


Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 25 Jul 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100