Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying a result in a textbox on a button click (ASP.Net) [closed]

Tags:

c#

.net

asp.net

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?

like image 320
sanakkian Avatar asked Jul 01 '11 05:07

sanakkian


2 Answers

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.

like image 185
Michael Shimmins Avatar answered Sep 22 '22 21:09

Michael Shimmins


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.

like image 21
Muhammad Akhtar Avatar answered Sep 22 '22 21:09

Muhammad Akhtar