Blog Stats
  • Posts - 14
  • Articles - 0
  • Comments - 14
  • Trackbacks - 0

 

Thursday, January 08, 2009

Scroll Div on page load

If you have a gridview/repeater control or other tabular data within a div, scroll bar appears when height  of data gets bigger than that of DIV.
If you want to scroll down to a certain position, you can use 'Element.scrollTop' property in Javascript:

document.getElementById(divWithScroll').scrollTop = PixelsToScroll;

Calculating the PixelsToScroll may vary depending on scenerio,

In my case, I wanted to scroll down to a selected row within Repeater control. Row was selected using RadioButton and page was reloaded on selection of RadioButton. So, I saved the SelectedItem.ItemIndex  in Repeater_ItemDataBound in a hidden field and using the value in Javascript like following:

PixelsToScroll = SelectedItem * 22;

where 22 is height of table row

Call OnClick Event of Button when Enter key pressed in TextBox

Problem: Say you have two Grid View controls on one page, each grid view has a TexBox and a 'search' button above it

TextBox1 btnSearch1                                       TextBox2 btnSearch2

Now if you press 'Enter' key  in TextBox1, it will trigger btnSearch1_click event and when you press 'Enter' key in TextBox2, it still triggers btnSearch1_click


Solution:  Add asp.net Panel tag and set DefaultButton property.

<asp:Panel ID="pnlSearch2" runat="server" DefaultButton="btnSearch2">
          TextBox2 btnSearch2
</asp:Panel>
 

Fixed Header for Data Repeater Control

I had a Repeater control within a div. Now when there were more records than visible within height of DIV a scroll bar appear. But, when user scrolls down, the headings ( within HeaderTemplate) would go up and not be visible.

After googling a little, I was able to find the solution on code project:

http://www.codeproject.com/KB/webforms/DataGridFixedHeader.aspx


In my case though I had a 'tr' element within 'HeaderTemplate' element ,so I applied it to like:

<tr class="ms-formlabel DataGridFixedHeader " >

Limitation:

It worked fine in IE 7, but in IE 6 the background image, if you have any in css,  would disappear on scrolling.
 

 

Copyright © faizanahmad