0

My situation looks like this: I've got x-axis scrollable div that contains buttons with numbers of page displayed. This div is placed in data list inside User Control responsible for displaying news on my site.

This is the code of this div and datalist with page numbers.

<div style="width:430px; overflow:auto; overflow-y:hidden; -ms-overflow-y:hidden; vertical-align:top; position:relative; top:-1px; ">
            <asp:DataList ID="dlPaging" runat="server" OnItemCommand="dlPaging_ItemCommand" RepeatDirection="Horizontal" 
                OnItemDataBound="dlPaging_ItemDataBound">
                <ItemTemplate>
                    <asp:Button ID="lnkbtnPaging" class="pagebutton" runat="server" CommandArgument='<%# Eval("PageIndex") %>'
                        CommandName="lnkbtnPaging" Text='<%# Eval("PageText") %>' CausesValidation="False" />
                </ItemTemplate>
            </asp:DataList>
            </div>

How to mantain x-axis position of this div after postback? I've tried several tricks, javascript and I can't figure it out.

user964986
  • 125
  • 1
  • 2
  • 10
  • Did you find any solution? I am in search of similar solution.. Please let me know if you have one. – CHash11 Apr 18 '14 at 11:23
  • I got it working. Please find my answer if at all you need it now..i know its toooo late, but i faced it recently and found solution. – CHash11 Apr 18 '14 at 12:50

2 Answers2

0
<div id="divDtPaging" runat="server" visible="true" style="width: 50%; overflow: scroll; text-align: center">
                            <asp:DataList runat="server" ID="dtPaging" OnItemCommand="dtPaging_ItemCommand"
                                OnItemDataBound="dtPaging_ItemDataBound" RepeatDirection="Horizontal"
                                SeparatorStyle-Wrap="true" Style="height: auto">
                                <ItemTemplate>
                                    <asp:LinkButton runat="server" ID="lnkbtnPaging" Text="PageText" CommandArgument="PageIndex" Style="padding-right: 5px">                                    
                                    </asp:LinkButton>
                                </ItemTemplate>
                            </asp:DataList>
                        </div>    
<asp:HiddenField id="hdnScrollPos" runat="server"/>

            <script type="text/javascript">
                function BeginRequestHandler(sender, args)
                {
                    document.getElementById('<%=hdnScrollPos.ClientID %>').value = document.getElementById('<%=divDtPaging.ClientID %>').scrollLeft;
                }
                function EndRequestHandler(sender, args) {
                    document.getElementById('<%=divDtPaging.ClientID %>').scrollLeft = document.getElementById('<%=hdnScrollPos.ClientID %>').value;
                }

                if (window.Sys && Sys.WebForms && Sys.WebForms.PageRequestManager) {
                    var prm = Sys.WebForms.PageRequestManager.getInstance()
                    prm.add_beginRequest(BeginRequestHandler);
                    prm.add_endRequest(EndRequestHandler);
                }

        </script>
CHash11
  • 746
  • 4
  • 14
  • 31
0

Any reason not to use an UpdatePanel?

sq33G
  • 3,320
  • 1
  • 23
  • 38
  • I can't make it work. I'm trying to add triggers but I'm failing at finding page button controls :/ It says that "A control with ID 'ContentPlaceHolder1_News1_dlPaging_lnkbtnPaging_0' could not be found for the trigger in UpdatePanel 'UpdatePanel2'." but when i look up generated HTML mark up the control ID is fine. I don't know what to do. Is it me or User Controls in asp.net sucks? – user964986 Oct 30 '11 at 22:40
  • Can we see the tag for the UpdatePanel? – sq33G Oct 31 '11 at 04:36