I ran into a bit of a silly problem. I have this piece of code with button values and method when pressed, but how do I get the button value itself to change the calculator screen?
<div class="text-center">
<div class="calc">
<div class="calc_screen">
<p>@equation</p>
</div>
<div class="calc_buttons">
<button class="calc_button ac bg-grey" value="AC" @onclick = "GetValue">AC</button>
<button class="calc_button plus-minus bg-grey" value="+/-" @onclick = "GetValue">>+/-</button>
<button class="calc_button percent bg-grey" value="%" @onclick = "GetValue">%</button>
<button class="calc_button division bg-orange" value="/" @onclick = "GetValue">/</button>
<button class="calc_button seven" value="7" @onclick = "GetValue">7</button>
<button class="calc_button eight" value="8" @onclick = "GetValue">8</button>
<button class="calc_button nine" value="9" @onclick = "GetValue">9</button>
<button class="calc_button multiply bg-orange" value="X" @onclick = "GetValue">X</button>
<button class="calc_button four" value="4" @onclick = "GetValue">4</button>
<button class="calc_button five" value="5" @onclick = "GetValue">5</button>
<button class="calc_button six" value="6" @onclick = "GetValue">6</button>
<button class="calc_button minus bg-orange" value="-" @onclick = "GetValue">-</button>
<button class="calc_button one" value="1" @onclick = "GetValue">1</button>
<button class="calc_button two" value="2" @onclick = "GetValue">2</button>
<button class="calc_button three" value="3" @onclick = "GetValue">3</button>
<button class="calc_button plus bg-orange" value="+" @onclick = "GetValue">+</button>
<button class="calc_button zero" value="0" @onclick = "GetValue">0</button>
<button class="calc_button dot" value="," @onclick = "GetValue">,</button>
<button class="calc_button equal bg-orange" value="=" @onclick = "GetValue">=</button>
</div>
</div>
</div>
@code{
private string equation = "0";
private void GetValue(){
equation = "some value of the button";
}
}
4
Answers
Try something like this:
For this type of thing, you need to pass the value into the event handler, like this
And, of course your handler needs to accept the value
Did you tried?
Try following code:
And don’t forget to use
StateHasChanged();
after calling methodes.Result: