I'm trying to use a validator. The problem is that when I run my code, the validator evaluates to true no matter what the input is. I have the following in an .ascx file:

Code:
<asp:Button ID="btn" runat="server" Text="submit" 
	CausesValidation="false" onclick="btn_Click" />  

<asp:TextBox ID="txtInput" runat="server" TextMode="SingleLine" 
	ReadOnly="false"></asp:TextBox>
   
<asp:RangeValidator id="RangeValidator1" Display="Dynamic" 
	ControlToValidate="txtInput" Type="Integer" 
	MinimumValue="0" MaximumValue="512" 
	ErrorMessage="There is an error in the input" runat="server" />
and I have this in the code behind:

Code:
protected void btn_Click(object sender, EventArgs e){	
	if (!RangeValidator1.IsValid) return;
}
RangeValidator1.IsValid, for some reason, always evaluates to true. How can I make validation work for the integer range of 0-512?