I'm trying to add 2 numbers and then show the result.
I have this in my aspx:
<asp:TextBox label="tal1" ID="TextBox_Tal1" runat="server"></asp:TextBox>
<asp:TextBox label="tal2" ID="TextBox_Tal2" runat="server"></asp:TextBox>
<asp:Button ID="Button_plus" runat="server" Text="+" OnClick="Button_plus_Click" />
<asp:Label ID="Label_plus" runat="server" Text=""></asp:Label>
And this in my .cs:
public int plus(int tal1, int tal2)
{
int result = tal1 + tal2;
return result;
}
protected void Button_plus_Click(object sender, EventArgs e)
{
int tal1 = Convert.ToInt32(TextBox_Tal1.Text);
int tal2 = Convert.ToInt32(TextBox_Tal2.Text);
plus(tal1, tal2);
}
Currently you're calling plus
, but ignoring the result. I suspect you want something like:
Label_plus.Text = plus(tal1, tal2).ToString();
That sets the content of the label which will then be rendered within the response.
Not sure if it makes sense to have a method for +
, or that it should be public, or that it should be called plus
in defiance of .NET naming conventions, but that's a slightly separate matter.
See more on this question at Stackoverflow