<div class="row mb10"> <asp:Label runat="server" ID="lbl_Adults" CssClass="col-lg-2 control-label" Text="Adults : " AssociatedControlID="txt_Adults"></asp:Label> <div class="col-lg-6"> <div class="col-lg-4" style="margin-left:-15px;"> <asp:TextBox runat="server" ID="txt_Adults" CssClass="form-control" OnTextChanged="txt_Adults_TextChanged" AutoPostBack="true"></asp:TextBox> <asp:RequiredFieldValidator Font-Bold="true" ForeColor="Red" runat="server" ID="req_Adults" ControlToValidate="txt_Adults" ErrorMessage="Enter No. of Adults"></asp:RequiredFieldValidator> </div> <div class="col-lg-8" style="font-family:'Copperplate Gothic'"> Only <asp:Label runat="server" ID="lbl_No_Of_Adults"></asp:Label> Adult(s) allowed. </div> </div> </div>
protected void txt_Adults_TextChanged(object sender, EventArgs e) { if (txt_Adults==null) { txt_Adults.Text = ""; txt_Adults.Focus(); } else if (Convert.ToInt32(txt_Adults.Text) > Max_NoAdults) { txt_Adults.Text = ""; txt_Adults.Focus(); } else if(Convert.ToInt32(txt_Adults.Text)<=Max_NoAdults) { NoAdults = Convert.ToInt32(txt_Adults.Text); } }
txt_Adults
if (txt_Adults.Text.Length != 0) { int32 tempValue; if (int32.TryParse(txt_Adults.Text, tempValue) == true) { // // tempValue now contains the integer value of the text // if (tempValue > Max_NoAdults) { txt_Adults.Text = ""; txt_Adults.Focus(); } else if(tempValue <= Max_NoAdults) { NoAdults = tempValue; } } else { txt_Adults.Focus(); } }
int32? tempValue; //nullable int variable
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)