Reputation: 1105
This is a simple question but I can't seem to find an answer. I want to use the stored value from one button click to another within the same form. Any assistance would greatly be appreciated. I tried using an example from Calling code of Button from another one in C# but could not get it to work.
public struct xmlData
{
public string xmlAttribute;
}
private void Show_btn_Click(object sender, EventArgs e)
{
xmlData myXML = new xmlData();
//do something.....
myXML.xmlAttributes = "blah"
}
private void Submit_btn_Click(object sender, EventArgs e)
{
//I want to call myXML.xmlAttributes retrieving the stored value from Show_btn_Click
}
Upvotes: 0
Views: 3055
Reputation: 2295
You should declare myXML variable at higher level of scope.
xmlData myXML = new xmlData();
public struct xmlData
{
public string xmlAttribute;
}
private void Show_btn_Click(object sender, EventArgs e)
{
//do something.....
myXML.xmlAttributes = "blah"
}
private void Submit_btn_Click(object sender, EventArgs e)
{
//I want to call myXML.xmlAttributes retrieving the stored value from Show_btn_Click
}
Upvotes: 2
Reputation: 37566
Instanciate the xmlData in the Constructor so you can access it overall in the class.
public class XYZ
{
xmlData myXML;
public XYZ()
{
myXML = new xmlData();
}
private void Show_btn_Click(object sender, EventArgs e)
{
//do something.....
myXML.xmlAttributes = "blah"
}
private void Submit_btn_Click(object sender, EventArgs e)
{
// Here you can work myXML.xmlAttributes
}
}
Upvotes: 2