[英]how to stop page jumping and maintain both panel & browser scroll position when user click on datalist item?
I have a datalist inside the panel 我在面板中有一个数据表
<asp:Panel ID="Panel1" runat="server" ScrollBars="Vertical">
<asp:DataList ID="DataList1" runat="server" RepeatDirection="Horizontal" OnItemDataBound="DataList1_ItemDataBound" CaptionAlign="Left">
<ItemTemplate>
<asp:ImageButton ID="btn1" runat="server" ImageUrl='<%#"~/Images.ashx?Name=" +DataBinder.Eval(Container.DataItem, "Path") %>'
OnCommand="Item_Command" CommandArgument='<%# Eval("Id").ToString() +";"+Eval("Path")%>' />
</ItemTemplate>
</asp:DataList>
</asp:Panel>
On Item_Command I am adding the style to btn1 such as border and color, and getting the id of selected item 在Item_Command上我将样式添加到btn1,例如border和color,以及获取所选项的id
string[] str = e.CommandArgument.ToString().Split(';');
Id = Convert.ToInt32(str[0]);
When I am selecting the item page is jumping, suppose I have scrolled browser scrollbar to bottom and selected an image browser scroll is going on top and again its coming on bottom, On Item_Command I am enabling and disabling few other btn which is out side of datalist, if i am keeping the datalist inside the updatepanel then all other btn is not getting enable or disable thats why i am not using update panel. 当我选择项目页面正在跳跃时,假设我已经将浏览器滚动条滚动到底部并选择了一个图像浏览器滚动正在顶部并且再次它在底部,On Item_Command我正在启用并禁用其他一些btn,这是在datalist,如果我将数据列表保留在updatepanel内,那么所有其他btn都没有启用或禁用这就是为什么我没有使用更新面板。 I have all the controls inside the update panel.
我在更新面板中有所有控件。 I tried with how to retain the browser scroll position after any event gets fire but its not working, i am setting
我尝试了如何在任何事件发生火灾后保留浏览器滚动位置,但它不起作用,我正在设置
Page.MaintainScrollPositionOnPostBack = true;
AutoEventWireup="true"
that also not working for me. 这也不适合我。 I am using VS 2010, 4.0 with C#.
我使用的是VS 2010,4.0和C#。
Some one plz tell me how to stop page jumping and maintain both panel1 and browser scroll position when user click on datalist item? 有人告诉我如何在用户点击datalist项目时停止页面跳转并保持panel1和浏览器滚动位置?
thanks in advanced.. 提前致谢..
Use a clientside function on Client click event of your image button like this 像这样在客户端点击事件的图像按钮上使用客户端功能
javascript:void(0);
的javascript:无效(0);
, it works for me in update panel, ,它在更新面板中适用于我,
<asp:ImageButton OnClientClick="javascript:void(0);" ID="btn1" runat="server" ImageUrl="~/Help2.png" AlternateText="asas"/>
Edit 编辑
UpdateMode=Conditional
的UpdateMode =条件
for the udpatePanel. 对于udpatePanel。
// Your image button event
//您的图片按钮事件
YourUpdatePanel.Update();
This coupled with what I posted earlier should fix your problem. 再加上我之前发布的内容应该可以解决您的问题。 Also you might not need MainScrollPositionOnPostBack=true by using above.
此外,您可能不需要使用上面的MainScrollPositionOnPostBack = true。
Damien. 达米安。
嗯,这就是想法:使用一个大的更新面板,覆盖整个页面以维护页面滚动或使用多个更新面板来覆盖您想要更新的所有项目!
尝试在Page标记内设置MaintainScrollPositionOnPostback
true:
<%@ Page (...) MaintainScrollPositionOnPostback="true" (...) %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.