Dictionary<string, string> propertyCompany = new Dictionary<string, string>();//gloabal variable
protected void Page_Load(object sender, EventArgs e)
{
if(!isPostBack){
propertyCompany .add("a","1");
propertyCompany .add("b","2");
propertyCompany .add("c","3");
}
}
protected void btnGetProperty_Click(object sender, EventArgs e)
{
string a=propertyCompany["a"];//error this key is not exist
//propertyCompany is null
}
when define a propertyCompany and fill in form_load. in on click button propertyCompany is null!?
i use a static but i does not understand sometime say error is null.
Each request creates new page object, therefore you cannot use in second request (bnt click) dictionary you have created in first request (load without postback)
Remove test for postback for quick fix.
Other fix posibilities:
* store dictionary in viewstate.