Wednesday, March 28, 2012

Change element on click

Hi,

I'm trying to create an AJAX-enabled control thas has the following functionality:

it's a Label that, when clicked, changes into a TextBox. The user can enter some text into the textbox en when he clicks outside the box (onblur) the textbox changes to a label again (now containing the entered text).

For this I created a server control inheriting from Label and a corresponding client control

The question is: can I change the displayed control in the _onClick event of the client control.

It should be something like:

_onClick : function(e){
this.element = $create(TextBox);
},

Does anyone know the right methods for this?

Thanks,

Thomas

Hmmm... I don't know if you can replace a control like that really. In that case, you would have to go to the parent element in the DOM tree, remove the label element and then add the text element. But that's very cumbersome.

What if you create both Label and TextBox and you toggle visibility on the two? Try changing the css attribute "display". Set it to block to show the element and none to hide it. Could help you with code in case you get stuck, just let me know. Good luck!

No comments:

Post a Comment