I have a fairly simple page - just has a listview on it, no paging. I'm using the rating control from the ajax toolkit within the listview. I have autopostback=true for the rating control. And when someone clicks a rating, my code updates a table in the
database, and then databinds the list view again so it will reflect the updated rating. When this happens, the whole pages refreshes and the user winds up back at the top of the page. I wouldn't mind so much about the refresh, if the user would not have to
scroll back down to where they were.
I thought dropping my listview in an UpdatePanel would fix the issue of the whole page refreshing, but it does not. I also put just the rating control in the update panel, but the whole page still seems to refresh.
Anyone know how i can resolve this? The main goal is to have the user remain where they were in the page after they rate something and NOT have to scroll back down to where they were.
edit: just discovered the MaintainScrollPositionOnPostback page property, which works for me. Although if there's a way to keep the page from refreshing and instead just have the specific record update on the page, that would be a nice bonus :)
Your work is not done by just putting that in update panel , you have to target the listview event which is causing postback , in update panel targetControlID set it as listview . You have to set the update panel with the control that is causing postback
, normally click or changed or checked event causes postback so target your controlID and event too.
Thank you for the reply. But I'm a little confused, since that article says:
Triggers for a given UpdatePanel, by default, automatically include any child controls that invoke a postback, including (for example) TextBox controls that have their
AutoPostBack
property set to true.
I do have the ajx rating control set to autopostback=true
The only control on the page which causes a postback is the rating control. The listview itself has no postback controls.
My code current looks something like this (i've removed some markup to keep it simple). Would i want to put the listview itself in the update panel? or just the rating control? I assume i have to put the whole listview in the update panel. Although i tried that and it did the same thing as if i put just the rating control in the update panel.
I enabled the viewstate on the listview1 as well as trying to set the childrenastriggers and updatemode, but the whole page is still refreshing. Just in case i did something stupid in my rating_changed function, here's the code for that:
Anyone have any other ideas why it is still doing a full page refresh? If you need any more info from me, please let me know. I can also put up a zip file of the full page code if that would help.
merk
Participant
766 Points
379 Posts
whole page getting refreshed
Jan 26, 2012 03:24 AM|LINK
Hi all,
I have a fairly simple page - just has a listview on it, no paging. I'm using the rating control from the ajax toolkit within the listview. I have autopostback=true for the rating control. And when someone clicks a rating, my code updates a table in the database, and then databinds the list view again so it will reflect the updated rating. When this happens, the whole pages refreshes and the user winds up back at the top of the page. I wouldn't mind so much about the refresh, if the user would not have to scroll back down to where they were.
I thought dropping my listview in an UpdatePanel would fix the issue of the whole page refreshing, but it does not. I also put just the rating control in the update panel, but the whole page still seems to refresh.
Anyone know how i can resolve this? The main goal is to have the user remain where they were in the page after they rate something and NOT have to scroll back down to where they were.
edit: just discovered the MaintainScrollPositionOnPostback page property, which works for me. Although if there's a way to keep the page from refreshing and instead just have the specific record update on the page, that would be a nice bonus :)
rating listview updatepanel
umairaslam22
Contributor
3990 Points
845 Posts
Re: whole page getting refreshed
Jan 26, 2012 04:07 AM|LINK
Your work is not done by just putting that in update panel , you have to target the listview event which is causing postback , in update panel targetControlID set it as listview . You have to set the update panel with the control that is causing postback , normally click or changed or checked event causes postback so target your controlID and event too.
http://www.asp.net/web-forms/tutorials/aspnet-ajax/understanding-asp-net-ajax-updatepanel-triggers
MCP
Blog
Please remember to Mark as answer if any post help you , it help others to find right solution in less time
merk
Participant
766 Points
379 Posts
Re: whole page getting refreshed
Jan 26, 2012 04:21 AM|LINK
Thank you for the reply. But I'm a little confused, since that article says:
Triggers for a given UpdatePanel, by default, automatically include any child controls that invoke a postback, including (for example) TextBox controls that have their
property set to true.I do have the ajx rating control set to autopostback=true
The only control on the page which causes a postback is the rating control. The listview itself has no postback controls.
My code current looks something like this (i've removed some markup to keep it simple). Would i want to put the listview itself in the update panel? or just the rating control? I assume i have to put the whole listview in the update panel. Although i tried that and it did the same thing as if i put just the rating control in the update panel.
<ajaxToolkit:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> </ajaxToolkit:ToolkitScriptManager> <asp:ListView ID="ListView1" runat="server" DataSourceID="sqlDsGames" DataKeyNames="ID,Rating" onitemcreated="ListView1_ItemCreated" EnableViewState="False"> <LayoutTemplate> <ul id="game-block"> <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> </ul> </LayoutTemplate> <ItemTemplate> <div class="rating-stars"> <asp:UpdatePanel ID="UpdatePanel1" runat="server" > <ContentTemplate> <ajaxToolkit:Rating ID="Rating1" runat="server" MaxRating="5" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar" FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar" OnChanged="Rating1_Changed" AutoPostBack="True" /></ContentTemplate> </asp:UpdatePanel> </div> </ItemTemplate> </asp:ListView>umairaslam22
Contributor
3990 Points
845 Posts
Re: whole page getting refreshed
Jan 26, 2012 06:09 AM|LINK
Put your update panel out of listview , means your listview alongwith rating control must be inside update panel.
<asp:UpdatePanel ID="UpdatePanel1" runat="server" > <asp:ListView ID="ListView1" runat="server" DataSourceID="sqlDsGames" DataKeyNames="ID,Rating" onitemcreated="ListView1_ItemCreated" EnableViewState="False"> <LayoutTemplate> <ul id="game-block"> <asp:PlaceHolder ID="itemPlaceholder" runat="server" /> </ul> </LayoutTemplate> <ItemTemplate> <div class="rating-stars"> <ContentTemplate> <ajaxToolkit:Rating ID="Rating1" runat="server" MaxRating="5" StarCssClass="ratingStar" WaitingStarCssClass="savedRatingStar" FilledStarCssClass="filledRatingStar" EmptyStarCssClass="emptyRatingStar" OnChanged="Rating1_Changed" AutoPostBack="True" /></ContentTemplate> </div> </ItemTemplate> </asp:ListView> </asp:UpdatePanel>MCP
Blog
Please remember to Mark as answer if any post help you , it help others to find right solution in less time
merk
Participant
766 Points
379 Posts
Re: whole page getting refreshed
Jan 26, 2012 11:16 AM|LINK
Hi, thanks.
I did try doing that, but it still looked like the whole page reloaded/refreshed when i did that.
sushanth009
Contributor
6243 Points
1168 Posts
Re: whole page getting refreshed
Jan 26, 2012 09:01 PM|LINK
Set the Update Mode to Conditional and SetChildrenAsTriggersTo = "False".. Try doing this to your update Panel
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="False" UpdateMode="Conditional"> <Triggers> <asp:AsyncPostBackTrigger ControlID="ListView1"> </Triggers> <ContentTemplate> // Your Code here </ContentTemplate> </asp:UpdatePanel>See if this works..
WishStar99
Contributor
2842 Points
865 Posts
Re: whole page getting refreshed
Jan 27, 2012 12:29 AM|LINK
Your code is fine. You need to set
EnableViewState="true"
on your ListView for it to work.
chetan.sarod...
All-Star
65709 Points
11133 Posts
Re: whole page getting refreshed
Jan 27, 2012 02:58 AM|LINK
http://forums.asp.net/t/1348432.aspx/1
https://forums.asp.net/p/1601152/4076297.aspx/1?Re+weird+Rating+Control+behavior
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
merk
Participant
766 Points
379 Posts
Re: whole page getting refreshed
Jan 27, 2012 06:46 AM|LINK
Thanks for the replies from everyone.
I enabled the viewstate on the listview1 as well as trying to set the childrenastriggers and updatemode, but the whole page is still refreshing. Just in case i did something stupid in my rating_changed function, here's the code for that:
protected void Rating1_Changed(object sender, RatingEventArgs e) { SqlConnection _conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ApplicationServices"].ConnectionString); _conn.Open(); string ip = Request.UserHostAddress; var cmd = new SqlCommand("AddVote", _conn) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.Add(new SqlParameter("@GameID", e.Tag)); cmd.Parameters.Add(new SqlParameter("@Vote", e.Value)); cmd.Parameters.Add(new SqlParameter("@IP", ip)); cmd.ExecuteNonQuery(); _conn.Close(); ListView1.DataBind(); }Anyone have any other ideas why it is still doing a full page refresh? If you need any more info from me, please let me know. I can also put up a zip file of the full page code if that would help.
Thank you everyone
WishStar99
Contributor
2842 Points
865 Posts
Re: whole page getting refreshed
Jan 27, 2012 07:26 AM|LINK
One thing i forgot to mention:
in your updatepanel, set updatemode=conditional
...
i copied your html code exactly how you posted it up top; and added my source from the code behind.
1) Enable viewstate on your ListView
2) add UpdateMode = Conditional to your UpdatePanel
... if it doesn't work, i can paste the sample code that i have here for you ...