populating a text box with FindControl
I have multiple textboxes and I want to programatically populate them with
the same method.
protected void PopulateAddress(string txtTextbox, Address adrAddress)
{
TextBox txtAddress = (TextBox)FindControl(txtTextbox);
txtAddress.Text = "Hello World";
}
the I call this method like below i get exception
PopulateAddress("tbxReturnAddress", CollectionAddress);
System.NullReferenceException: Object reference not set to an instance of
an object.
and it highlights the txtAddress.Text = "Hello World"; line.
I'd like to do it like this with the method because there are three
address separate addresses that I need to populate on the form but I'd
like to try using re-usable code to do it by feeding in the address object
and the textbox id.
What am I missing?
No comments:
Post a Comment