In: Computer Science
Suppose an application’s GUI has two TextBox controls named inputTextBox and outputTextBox. Write C# statement(s) that display the text entered by the user in the inputTextBox to the outputTextBox.
Write a statement for shifting focus to the textbox control nameTextBox.
Assume that we have a listbox control stateListBox. Add the item “Florida” to the list box.
Find the following steps as per required :
Step 1:
Create a new website with language as C#
Step 2 :
The project looks like as shown below in attached screenshot :
Step 3:
From the Toolbox shown in the figure add the controls . Just drag and drop the control in the design view as shown in the attached screenshot with explanation
Step 4 :
Now click on the source view . Add the code as shown below :
We are adding one textbox named inputTextBox . Another named outputTextBox as shown below :
<asp:TextBox ID="inputTextBox" name="inputTextBox" runat="server" AutoPostBack="true" OnTextChanged="inputTextBox_TextChanged"></asp:TextBox>
<td><asp:TextBox ID="outputTextBox" name="outputTextBox" runat="server" AutoPostBack="true"></asp:TextBox></td>
<asp:ListBox ID="ListBox1" runat="server">
<asp:ListItem>Georgia</asp:ListItem>
</asp:ListBox>
Step 5 :
As per required , we need to add an event i.e onTextChanged fwhen inputTextBox is changed . This will invoke the method named inputTextBox_TextChanged when text in the inputTextBox is changed as shown in below figure
<asp:TextBox ID="inputTextBox" name="inputTextBox" runat="server" AutoPostBack="true" OnTextChanged="inputTextBox_TextChanged"></asp:TextBox>
Step 6:
To display the entered text in the outputTextBox , we need to use below code . I.e assigning the value of inputTextbox to outputTextbox with the following command :
// Assigning value
outputTextBox.Text = inputTextBox.Text;
Step 7 : Adding Focus to nameTextBox
Using below command add focus to nameTextBox
// Adding focus to nameTextBox
nameTextBox.Focus();
Step 8 : Adding item to list box
To add an item to list box we need to use items.Add
Code is as below :
// Adding item to list box
ListBox1.Items.Add("Florida");
Step 9: Run the Program :
Initial screenshot which displays the textboxes , list control as required .
Step 10 :
Enter text in the input textbox . Then the entered text is shown in the Output Text box . The focus is changed to the nameTextbox . And the item Florida is added to the List as shown in the below attached screenshot :
Step 11 : The final code is as below :