Hey I have a Terms and Conditions Text area which has a scroll bar and a normal ASP.NET button below that.
I was wondering how could I disable this button till the user scro开发者_运维百科ll till the end of terms and conditions.
This is something that's best accomplished client-side - are you already using a library such as jQuery or something else?
Setting up the following works a treat:
<asp:TextBox runat="server" id="termsConditions"
TextMode="MultiLine" Rows="10" Columns="50">
Lots of text here[...]
</asp:textbox>
<asp:button runat="server" id="accept" text="Accept" />
<script type="text/javascript">
// Using jQuery, other options are available
// pick up the button, and disable it, keeping the button for later.
// Note the use of the ClientID property of the ASP.NET controls - this allows
// us to cleanly pick up the client side id of the objects.
var button = $("#<%= accept.ClientID %>");
button.attr("disabled", "disabled");
// pick up the textarea.
var terms = $("#<%= termsConditions.ClientID %>");
// bind to the textarea's scroll event
terms.scroll(
function () {
// Compare the scollHeight (the complete height of the textarea), with the
// combination of the current position (scrollTop) and the offsetHeight.
if (terms[0].scrollHeight < (terms[0].offsetHeight + terms[0].scrollTop)) {
// Re-enable the button
button.attr("disabled", null);
}
});
</script>
ours is not to reason why, here's an example
http://www.27seconds.com/kb/article_view.aspx?id=56
精彩评论