alex_stock
alex_stock

Reputation: 35

How to return answer from textbox

I have some code where a user inputs some information into a textbox and I want to return that information as a string that I can access from other places in the code. (subquestion - I've searched everywhere - what's the name for blocks of code under something like "Private void")

private string SearchJobNoTextBox_TextChanged(object sender, EventArgs e)
{
  string sSearchJobNo = SearchJobNoTextBox.Text;
  return sSearchJobNo;
}

Upvotes: 0

Views: 647

Answers (1)

Andrey Korneyev
Andrey Korneyev

Reputation: 26876

Your method handling TextChanged event can't return anything, it should be void.

Also - you can access this textbox text anywhere in your form class. If you need to get it somewhere outside your form - you can create public (or internal - depending on scope you need to access it) method (or property) returning it.

Something like

public string SearchJobNo
{
    get { return SearchJobNoTextBox.Text; }
}

Then you will be able to access this value as yourform.SearchJobNo

And answer on your subquestion: name for blocks of code under something like "Private void" - is "method".

Upvotes: 3

Related Questions