Attempting something like
public string MyText { get {return lbl.Text;} set {lbl.Text = value;}}
taken from this question ends in an exception:
public string change_ddlArea { get { return ddlArea.SelectedItem.Text; } set { ddlArea.Items.FindByValue(value).Selected = true; } }
–> Object reference not set to an instance of an object.
Using these normally cause the same error:
this.ddlEnergyType.Items.FindByValue(resourceTypeVal).Selected = true;
((DropDownList)Master.FindControl("ddlArea")).Items.FindByValue("all").Selected = true;
I’m having difficulty finding an answer to this problem on google. It should work, given if a label manipulation does, moving to a ddl would as well?
The one difference that could be the problem is when trying to call this.. (in the 2nd code block) I use
Master.change_ddlArea = sendoff_area;
and in the aformentioned link it is done like so
((MasterPageTypeName)Page.MasterPage ).MyText = "test";
//so mine would look like this:
((GAWMaster)_default.Master).change_ddlArea = "all";
however intellisense is missing the ‘.Master’ – putting it in causes the information to appear: an object reference is required for the non-static field, method or property….
tl,dr: halp
Your question is VERY confusing to say the least. It’s very simple to do what your title is asking:
First in your
MasterPagecode behind do:Then in your child page define your
MasterPagetype so that it can ‘see’ thechange_ddlAreaproperty of theMasterPage. See here for more reference info.Then in your code on your child page you should be able to just do:
The value you are setting MUST exist or you will get an object reference error. Make sure your
DropDownListis loaded correctly and you are not doing things out of order. Also, if your not usingViewStateand doing aPostBack, make sure you have rebuilt yourDropDownListbefore setting the value.