lundi 25 janvier 2021

Checkbox to control rangevalidator or maximum input double of textbox

I have a checkbox and the goal is to limit the maximum input value of a textbox when the checkbox is ticked.

I have two solutions in mind , one is to alter the value of the rangevalidator when the checkbox is ticked or the other is to restrict the value parsed into the textbox when the checkbox is ticked.

But my latter solution has an error as seen in the image below. While i don't know how to implement the former solution.

Code of the TextBox

<div class="d flex justify-content-start">
                    <div class="col-6 ">
                        Hours Spent
                            <asp:TextBox placeholder="Hours Spent *" Width="" ID="txtHoursSpent" runat="server" MaxLength="3"></asp:TextBox>
                        <asp:RangeValidator ID="RangeValidator1" runat="server" ErrorMessage="Value must be greater than zero."
                            ValidationExpression="\d+" ControlToValidate="txtHoursSpent" MinimumValue="0.5" MaximumValue="12" Type="Double"></asp:RangeValidator>

                    </div>
                </div>

Code Of the CheckBox

<asp:CheckBox Text="Half-Day" runat="server" OnCheckedChanged="HalfDay_CheckedChanged" />

As you can see the error in the codebehind causes me to be unable to restrict the textbox to a certain range. Code Behind of the Checkbox

Does anyone know the solution perhaps?




Aucun commentaire:

Enregistrer un commentaire