I found an interesting article on how to create a Combo Box in DHTML. Form controls are definitely in need of the combo box, but I’m not so sure this does the job all that well.
http://www.tgreer.com/comboArticle.html.
A combo box is a drop down select list that can also allow the user to input his or her own strings. The author of the article builds one in DHTML by first placing a select list on the page and then placing a textbox on top of it using CSS. He then causes the dropdown list to make a Javascript function call, causing the textbox to update with the value of the list’s selection. It’s interesting in concept, but you can tell something strange is happening. Looking at the page, you can tell there’s a rendering error (in this case not an error) and that there are controls stacked on top of each other.
Tag Archives: DHTML
Getting Vertical Scroll Position in a Div to Persist Across Postbacks
I’ve been working on this for a little bit now, and it was surprisingly easy. I just didn’t know all of the syntax.
First, any element in a webpage that scrolls has a scrollTop attribute that’s equal to the number of pixels it has been scrolled. When it’s scrolled all the way to the top, scrollTop is zero.
To cause this to persist, you can store it in a hidden input.
<input type=”hidden” name=”whatever” id=”whatever” value=”default” runat=”server”>
Name and id should be equal, and making sure runat=”server” is present is important. Now this should persist automatically. The only other thing that’s needed is to store and restore the value. You can use an onscroll=”nameOfJavascriptFunctionThatStoresThePosition()” attribute in the div in question to call a function whenever the div is scrolled. Then in your Javascript section, set window.onload equal to whatever function is going to restore it. Parentheses aren’t needed at the end because you’re mapping onload to a function.
The last thing to remember is that in your storing and restoring functions, you can’t simply refer to the id of the hidden input because your codebehind might, and most likely will, change it. You’d have to use <%=idOfInput.ClientID%>. You can use document.getElementById(‘ blah ‘).value, where blah is that previous tag. To restore the value that value should be set into the div’s scrollTop (again, you can use document.getElementById(), but you won’t need to do ClientID stuff because the div’s not runat=”server”. To store the value, you just set the scrollTop into that hidden input using that same method. Pretty simple!
Of course, if you’re not concerned with a div but rather the whole document, you can do a similar thing using body’s scrollTop or just enable SmartNavigation if the page is being designed for InternetExplorer.
