1

I know there have been alot of similar questions (I've checked Google) as the one I'm asking now. I've tried all the options/suggestions I've read about on Google, but still does not work for me. I've tried adding "maintainScrollPositionOnPostBack=true" to the top of my page, tried adding it to my web.config file, also I've commented out all of the .Focus on my controls because I read somewhere that it will override the maintainScrollPositionOnPostback. Nothing works for me for some reason.

Just a little context:

I have a drop down list that has a corresponding textbox that appears when the list item is selected by the user. With maintainScrollPositionOnPostback=true; when I select that particular list item choice, the page scrolls to the top of the page then scrolls back to where the drop down list and textbox is located. It's a little annoying because I have a bunch of drop down lists on this one page and every time the users selects an item, it would behave the way it is now..

spades0001
  • 55
  • 7
  • Use javascript to postback the selected item from the list. Read this to learn how to do it: https://stackoverflow.com/questions/3713/call-asp-net-function-from-javascript – D A Sep 26 '22 at 05:45

1 Answers1

1

when I select that particular list item choice, the page scrolls to the top of the page then scrolls back to where the drop down list and textbox is located.

Then you back to the correct scoll position and it works - just not all that great.

You don't mention how many combo (drop down list (ddl)) boxes you have.

Two solutions.

Use client side JavaScript for the ddl to hide/show the text box. Had you posted some of your markup, I could have posted some simple JavaScript code that hides/shows the text box. But, without us here seeing the markup, it beyond hard to do so.

The next idea? Use a update panel.

So, drop in right after the form tag a scrip manager control.

Then where your 3-4 ddl''s are?

Do this, so right after form tab, add script manager.

<form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>

Then down in the page where the 3-4 dll's are, do this:

        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>

  ----> your 3-4 ddl's and text boxes go here.

            </ContentTemplate>
        </asp:UpdatePanel>

So, try the above - a update panel will do what we call a "partial" page post-back - the screen will not jump. And in fact, you can remove the maintainScrollPositionOnPostback.

Albert D. Kallal
  • 42,205
  • 3
  • 34
  • 51
  • Thank you! Using the UpdatePanels worked for me. I listened to your advice and placed all of my controls into UpdatePanel, and then on my master page, I placed a ScriptManager. Really appreciate your time thank you – spades0001 Sep 28 '22 at 05:46
  • As noted, you don't necessary want to place ALL controls in the Update panel. But, only that section of the page that has those drop downs. But, regardless, great to see this works. – Albert D. Kallal Sep 28 '22 at 16:16