页面在ASP.NET Webforms中单击按钮时向上滚动 [英] Page is Scrolling Up When Clicked On Button In ASP.NET Webforms

查看:100
本文介绍了页面在ASP.NET Webforms中单击按钮时向上滚动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi


我有一个页面有50种类型的产品采用Datalist和每种产品我在那里放了一个按钮添加到购物车。

我的问题是,当我点击产品的按钮添加到购物车,然后页面始终滚动到顶部位置。

如何停止滚动页面按钮是点击..

一个人帮助我...提前谢谢...



我使用的设计代码:



hi
I Have a Page With 50 Types Of Products Taken In Datalist And For Each Product There I Had Put A Button "Add To Cart".
My Problem Is That When I Click On The Button "Add To Cart" Of A Product, Then The Page Is Scrolling To Top Position Always.
How To Stop The Scrolling Of A Page When Button Is Clicked..
Some One Help Me..Thanks In Advance...

The Designing Code I Had Used :

<%@ Page Language="C#" MasterPageFile="~/MasterPage.Master" AutoEventWireup="true" MaintainScrollPositionOnPostback="true"

    CodeFile="Products.aspx.cs" Inherits="Library" Title="Products Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <br />
     <asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1"

        DataKeyField="ProductID"

        onselectedindexchanged="DataList1_SelectedIndexChanged" RepeatColumns="3" RepeatDirection="Horizontal"

    BorderColor="#336699" BorderStyle="None" BorderWidth="2px" Width="747px">
            <ItemTemplate>
                <%--ProductID:--%>
                <asp:Label ID="ProductIDLabel" runat="server" Text='<%# Eval("ProductID") %>' Visible="false"/>
                <br />
                <br />

                <asp:Label ID="ProductNameLabel" CssClass="class1" runat="server"

                    Text='<%# Eval("ProductName") %>' />
                <br /><br />
                <asp:Image ID="Image1" runat="server" CssClass="class1" ImageUrl='<%# Eval("ProductImage") %>' Height="100" Width="150"/><br />
                <asp:Label ID="ProductImageLabel" runat="server" Text='<%# Eval("ProductImage") %>' Visible="false" /><br />
                <br />
                <asp:Button ID="lnkSelect" runat="server" CommandName="Select" Text="Add To Cart" />
                Price:
                <asp:Label ID="ProductPriceLabel" runat="server" Text='<%# Eval("ProductPrice") %>' />

                <br />

            </ItemTemplate>
            <ItemStyle HorizontalAlign="Center" VerticalAlign="Top" />
        </asp:DataList>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"

            ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

            SelectCommand="SELECT [ProductID], [TypeOfImage], [ProductName], [ProductDescription], [ProductPrice], [ProductImage] FROM [tblImages] WHERE ([TypeOfImage] = @TypeOfImage) ORDER BY ProductName">
            <SelectParameters>
                <asp:ControlParameter ControlID="DataList1" DefaultValue="Products"

                    Name="TypeOfImage" PropertyName="SelectedValue" Type="String" />
            </SelectParameters>
        </asp:SqlDataSource>

</asp:Content>

推荐答案

ConnectionStrings:ConnectionString %>

SelectCommand = SELECT [ProductID],[TypeOfImage],[ProductName],[ProductDescription],[ProductPrice], [ProductImage] FROM [tblImages] WHERE([TypeOfImage] = @TypeOfImage)ORDER BY ProductName >
< SelectParameters >
<
asp:ControlParameter ControlID = DataList1 DefaultValue = 产品

名称 = TypeOfImage PropertyName = SelectedValue 类型 = 字符串 / >
< / SelectParameters >
< / asp:SqlDataSource >

< / asp:内容 >
ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [ProductID], [TypeOfImage], [ProductName], [ProductDescription], [ProductPrice], [ProductImage] FROM [tblImages] WHERE ([TypeOfImage] = @TypeOfImage) ORDER BY ProductName"> <SelectParameters> <asp:ControlParameter ControlID="DataList1" DefaultValue="Products" Name="TypeOfImage" PropertyName="SelectedValue" Type="String" /> </SelectParameters> </asp:SqlDataSource> </asp:Content>


我得到了解决方案:



MaintainScrollPositionOnPostback属性在Firefox和Chrome中不起作用并提供了一个适用于所有的解决方案主要浏览器Internet Explorer IE,FireFox,谷歌浏览器,Apple Safari和Opera。



我提到了下面的链接,它提供了在WintainScrollPositionOnPostback In上运行良好的Javascript代码所有浏览器

http://www.aspsnippets.com/Articles/ASPNet-MaintainScrollPositionOnPostback-not-working-in-Firefox-and-Chrome.aspx
I Got The Solution:

MaintainScrollPositionOnPostback Property is not working in Firefox and Chrome and provided a solution that works in all major browsers Internet Explorer IE, FireFox, Google Chrome, Apple Safari and Opera.

I refered The Below Link , It Gives The Code In Javascript That Works Well On MaintainScrollPositionOnPostback In All Browers
http://www.aspsnippets.com/Articles/ASPNet-MaintainScrollPositionOnPostback-not-working-in-Firefox-and-Chrome.aspx


我希望你在href中使用#tag。



使用javascript:void(0)而不是#



请检查一下。



http: //stackoverflow.com/questions/134845/href-attribute-for-javascript-links-or-javascriptvoid0 [ ^ ]
I hope you are using # tag in href.

Use "javascript:void(0)" instead of "#"

Please check this.

http://stackoverflow.com/questions/134845/href-attribute-for-javascript-links-or-javascriptvoid0[^]


这篇关于页面在ASP.NET Webforms中单击按钮时向上滚动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆