c# - NullReferenceException on textbox -



c# - NullReferenceException on textbox -

this question has reply here:

what nullreferenceexception , how prepare it? 21 answers

i have simple button click method sets textbox's text viarable textfromtb.

private void button1_click(object sender, eventargs e) { string textfromtb = textbox1.text; }

if run once, okay, set text textbox1 textfromtb. if run method sec time throws nullreferenceexepction. why that?

i tried initialize textbox that

private void button1_click(object sender, eventargs e) { textbox textbox1 = new textbox(); string textfromtb = textbox1.text; // line returns null }

but sets textbox1.text null or empty string. how can alter code work multiple times without exceptions?

thanks in advance!

are sure it's textbox null , not textfromtb ?

c# visual-studio visual-studio-2012 nullreferenceexception

Comments

Popular posts from this blog

java Multi query from Mysql using netbeans -

c# - DotNetZip fails with "stream does not support seek operations" -

c++ - StartServiceCtrlDispatcher don't can access 1063 error -