using System;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI;
namespace yaf.controls
{
///
/// Summary description for SmartScroller.
///
public class SmartScroller : System.Web.UI.Control
{
private HtmlForm m_theForm = null;
private HtmlInputHidden hidScrollLeft = new HtmlInputHidden();
private HtmlInputHidden hidScrollTop = new HtmlInputHidden();
public SmartScroller()
{
}
private HtmlForm GetServerForm(ControlCollection parent)
{
HtmlForm tmpHtmlForm = null;
foreach (Control child in parent)
{
Type t = child.GetType();
if (t == typeof(System.Web.UI.HtmlControls.HtmlForm))
return (HtmlForm)child;
if (child.HasControls())
{
tmpHtmlForm = GetServerForm(child.Controls);
if (tmpHtmlForm != null && tmpHtmlForm.ClientID != null)
return tmpHtmlForm;
}
}
return null;
}
protected override void OnInit(EventArgs e)
{
string tFormID = "Form";
if (Page.Parent != null)
m_theForm = GetServerForm(Page.Parent.Controls);
else
m_theForm = GetServerForm(Page.Controls);
if (m_theForm != null && m_theForm.ClientID != null)
{
tFormID = m_theForm.ClientID;
}
hidScrollLeft.ID = "scrollLeft";
hidScrollTop.ID = "scrollTop";
this.Controls.Add(hidScrollLeft);
this.Controls.Add(hidScrollTop);
string scriptString = @"
";
Page.ClientScript.RegisterStartupScript(Page.GetType(),"SmartScroller", scriptString);
}
protected override void Render(HtmlTextWriter writer)
{
Page.VerifyRenderingInServerForm(this);
base.Render(writer);
}
public void Reset()
{
hidScrollLeft.Value = "0";
hidScrollTop.Value = "0";
}
}
}