Display radio button selection in Label without submitting the button twoway binding

Kalyan A 185 Reputation points
2024-10-02T16:43:51.61+00:00

I want to display the Radio button Selection in a Label (example Area/Perimeter),without submitting the button two way binding, please suggest.

@page "/SquareSide"
@using System.ComponentModel.DataAnnotations;
@using MauiAppMCQs.Models;
@using static MauiAppMCQs.Models.ComponentEnums;
<h3>Square Area or Perimeter</h3>
<PageTitle>Square</PageTitle>
<div >
    <fieldset disabled=@isdisabled>
        
        <InputRadioGroup @bind-Value="Calulation" >
            @foreach (var calculationItem in Enum.GetValues<Calulation>())
            {
                <div>
                    <label>
                        <InputRadio Value="calculationItem" />
                        @calculationItem
                    </label>
                </div>
            }
        </InputRadioGroup>
    </fieldset>
    <fieldset>
        <legend>Enter Value  </legend>
        <InputNumber @bind-Value="num1"  disabled=@isdisabled />
        <button @onclick="Calculate" disabled=@isdisabled>
            Calculate
        </button>
    </fieldset>
  <br >
    <p>@calcx</p>
  <br >
    
    
    <fieldset>
        <legend>Side</legend>
        <div>@Side</div>
    </fieldset>
    <br>
    <button @onclick="Clear" >
        Clear
    </button>
    <br />
    @errmsg
</div>
@code {
    [Required, EnumDataType(typeof(Calulation))]
    public Calulation? Calulation { get; set; } = MauiAppMCQs.Models.ComponentEnums.Calulation.Area; public string skip; public string type;
    private bool isdisabled = false; public string errmsg = ""; public string calcx = "";
    public class ComponentEnums
    {
        public enum Calulation { Perimeter, Area }
    }
    public double  Side   ;
    public double  num1   ;
    private void Calculate()
    {
        if (num1 > 0)
        {
            isdisabled = true;
        }
        errmsg = "";
        skip = "N";
        if ((num1 <= 0))
        { skip = "Y"; isdisabled = false; }
        if ((num1 > 2000))
        { skip = "Y"; isdisabled = false; }
        if (skip == "N")
        {
            if (Calulation == MauiAppMCQs.Models.ComponentEnums.Calulation.Area)
             
            { Side = Math.Round(Math.Sqrt(num1), 1); calcx = "Input is Area"; }
        else
            { 
                if (Calulation == MauiAppMCQs.Models.ComponentEnums.Calulation.Perimeter)
                {
                    calcx = "Input is Perimeter";
                    Side = Math.Round((num1 / 4), 1); }
                else
                { errmsg = "Check a Radio Button"; }
            }
        }
        else
        { errmsg = "Enter a number between 1 and 2000"; }
    } 
    private void Clear()
    { num1 = 0; isdisabled = false; Side = 0; calcx = ""; }
}
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,471 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 64,826 Reputation points
    2024-10-02T19:50:35.4033333+00:00

    then add a click handlers for the radio buttons. pass the value to the click handler

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.