当我单击 Add Dependent 链接按钮时,我希望滚动条滚动到底部,这很有效。问题是当回发后选择添加相关链接按钮时,文本“<em>请修复以下问题:”会显示一秒钟。但是,它下面没有错误消息。如果存在验证问题,验证(jQuery-validation 插件)可以正常工作。
谢谢。
这是相关的asp.net代码:
<script type="text/javascript" language="javascript">
function toBottom(id) {
document.getElementById(id).scrollTop = document.getElementById(id).scrollHeight
}
</script>
<div id="divscroll" class="scroll">
</div>
<div id="validationMessageContainer" class="error" >
<span id="info_dep_fix_problemls">Please fix the following problems:</span>
<ul></ul>
</div>
<asp:LinkButton ID="AddDependent" Text="Add Dependent" CssClass="btngeneral" OnClientClick="toBottom('divscroll')"
OnClick="AddDependent_Click" runat="server" />
后面的 C# 代码:
protected void AddDependent_Click(object sender, EventArgs e)
{
//Other unrelated code -- the button has to be server side as we do database connections, etc.
getScrollPosition();
}
protected void getScrollPosition()
{
//Sets the scroll position of the divscroll to the bottom on postback
ClientScript.RegisterStartupScript(this.GetType(), "toBottom", "toBottom('divscroll')", true);
}
这是滚动div的css。
div.scroll
{
-ms-overflow-x:hidden;
overflow-x:hidden;
-ms-overflow-y:auto;
overflow-y:auto;
max-height: 400px;
max-width: 900px;
}