Domanda

I have DropDownList and a TextBox in the EditTemplate of my FormView. All I want is to enable/disable the TextBox based on whether the first entry of my DropDownList is selected:

  1. When the FormView is switched to Edit mode by the user
  2. When user changes the selected item of the DropDownList during Edit mode.

I have achieved the second one through JS and that's working fine, but the first one is proving too difficult. I've tried to do this in ModeChanged event of the FormView, but for some reason the following call returns null in the event:

MyFormView.FindControl("MyDropDownListID");

What am I missing here?

(I'm making sure that MyFormView.CurrentMode is FormViewMode.Edit before making the above call)

È stato utile?

Soluzione

One of those times when you pull your hair for hours with a problem, then post it on SO and find the solution in the next few minutes. Anyone else trapped into this, the problem is that the controls of a databound FormView aren't created yet at the time of ModeChanged or Page_Load. You must call the above line in DataBound event and it will work fine.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top