Pregunta

Estoy tratando de incluir un control de imagen dentro de mi pieza de la tela. En EnsureChildControls tengo el siguiente código:

Image image = new Image();
image.ImageUrl = this.Page.ClientScript.GetWebResourceUrl(this.GetType(), "hotline.jpg");

recibo una excepción NullPointer y esto se debe a 'Página' es nulo.

¿Por qué puede ser esto? Estoy haciendo esto todos modos mal?

¿Fue útil?

Solución

Be sure not to call EnsureChildControls() from within the constructor of your WebPart.

Also, I would not override EnsureChildControls but override CreateChildControls instead, as James and Wictor have already mentioned in their answers.

Otros consejos

Are you calling the parent EnsureChildControls() at the start of your overridden method?

Also, have you tried your code in CreateChildControls()?

Can you give us some more details on how you run this Web Part, for instance in which context?

How do you call EnsureChildControls and why are you adding the image there and not in CreateChildControls?

Licenciado bajo: CC-BY-SA con atribución
scroll top