Displaying the result in a text box when a button is clicked (ASP.Net)

I am new to ASP.Net and would like to help with a simple script:

Currently, in my web application, I have one button and one text box in my web application. When I click the button, I want to display the result in a text box.

How can I do it?

+7
source share
6 answers

If you use ASP.NET WebForms, you can add a Click event handler to the button to set the text of the text field:

protected void Button1_Click(object sender, EventArgs e) { MyTextBox.Text = "Text to display"; } 

You can use autowireup to get the event handler connected to this button, or explicitly assign the event handler to the event in the Page_Load () method.

The easiest way to assign an event to a button is to declare it in .aspx code, for example:

 <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" /> 

This will be done automatically if you double-click this button in design mode.

+7
source

You can set the result by clicking the Click Handler button, as ...

 protected void Button1_Click(object sender, EventArgs e) { TextBox1.Text = "Result Text....."; } 

There is a Text property for Textbox controls that is used for Set/Get values.

+3
source
  public void button_Click(object sender, CommandEventArgs e) { txt.Text = "Testing"; } 
+2
source

lambdas anyone ???

 button.Click += (s, e) => { textbox.Text = "whoa!"; } 

Hmm?

+2
source
 public void button_Click(object sender, EventArgs e) { string str="String"; int i=100; textbox1.Text = "string text"; //or textbox1.Text = str; //or textbox1.Text = i.Tostring(); //and same as above for other types ie, convert to string when assigning to textBox because textbox takes value as string only } 
+1
source
 protected void Button1_Click(object sender, EventArgs e) { TextBox1.Text = "Text Message"; } 

Send this link to get started: http://www.knowdotnet.com/

For submit button properties, check this: MSDN button control

0
source

All Articles