I am new to ASP.Net and would like some help with a simple scenario:
Currently in my web application I have one button and one textbox in my web application. When I click the button I want to display a result in the text box.
How should I do this?
If you're using ASP.NET WebForms you can add a Click event handler to the button to set the text box's text:
protected void Button1_Click(object sender, EventArgs e)
{
MyTextBox.Text = "Text to display";
}
You can either use autowireup to get the event handler wired to the button, or explicitly assign the event handler to the event in the Page_Load() method.
The easiest way to assign the event to the button is to declare it in the .aspx code like this:
<asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
It will be done automatically if you doubleclick this button in the designer mode.
You can set the result in a button Click Handler like...
protected void Button1_Click(object sender, EventArgs e)
{
TextBox1.Text = "Result Text.....";
}
There is a Text
property of Textbox controls, that is used to Set/Get
values.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With