简体   繁体   English

当用户点击datalist项目时,如何停止页面跳转并维护面板和浏览器滚动位置?

[英]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 编辑

  1. Put the button & datalist inside a updatePanel. 将按钮和datalist放在updatePanel中。 Set

UpdateMode=Conditional 的UpdateMode =条件

for the udpatePanel. 对于udpatePanel。

  1. When you perform your operation on the dataList row. 在dataList行上执行操作时。 Just update the update panel manually like this 只需像这样手动更新更新面板

// 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.

相关问题 调整浏览器窗口大小时如何停止页面刷新(跳转)? - how to stop Page refreshing ( Jumping) when The browser window is resized? 如何停止数据列表项目模板中的页面跳转复选框? - How to stop page jumping checkbox check which is inside the datalist itemtemplate? 在GridView中添加动态行时如何保持页面的滚动位置? - How to maintain scroll position of a page when add dynamic rows in GridView? 如何在回发时保持特定页面的滚动位置 - How to maintain scroll position of specific page on postback 当该文本框上的iframe控件具有焦点时,如何保持页面的滚动位置? - How to maintain scroll position of page when it has iframe control on that textbox has focus? 如何在自动回发时保持滚动位置? - How to maintain scroll position on autopostback? 在updatepanels而不是页面中保持列表框中的滚动位置 - Maintain scroll position in listboxes in updatepanels, NOT the page 单击同一页面上的按钮后如何维护下拉列表中的所选项目 - how to maintain dropdownlist selected item after click of a button on the same page 保持滚动位置与母版页异步部分页面回发Ajax - Maintain Scroll Position Asynchronous Partial Page Postback Ajax With Master Page Telerik RadNotificationMessage不维护IE8中的页面滚动位置 - Telerik RadNotificationMessage does not maintain page scroll position in IE8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM