Changing container style at runtime

I have a container that I am using as part of dynamic control and I want to change the style used on every other time I use it but no matter where I set the I get a javascript error. Is this to be expected, can you not change the style at runtime without using WCC?

Does this help? I had a similar question a while back.

Try setting in the Container’s Shown event. Doing it immediately after creation seems to be triggering the JavaScript errors. i.e.:

c = new MyContainer c.EmbedWithin(self, 0, 0, 200, 100) = stMyStyle

Instead, move the last line into MyContainer.Shown. I know it’s screwy, and it shouldn’t be this way, but that’s how to get around the issue for now.

Still blows up in the Shown event.

Are you setting any other properties of the dynamic control outside the Shown event?

I have stripped everything out to whats below, I have removed each part and found that the error only occurs when I include the style:

c.LockLeft = true c.LockRight = true c.LockTop = true c.EmbedWithin(me, 0, session.pPrescriptionPadOffset, myControlWidth, c.Height) = stMyStyle c.ScrollbarsVisible = 2 c.lblProductName.Text = aryPrescriptionPad(lp).ProductName c.ID = lp

The only way I can get what I want is to create a rectangle on the control and set in invisible and with the style I want the alternate to be. Then in the open event of the container I set the zindex to -2000. When the container is created as a dynamic control I decide if the loop is odd or even and then turn the rectangle visible for the rows I want to have the different style background. This appears to work but is very messy.

Try it in the Open event…

No it still fails but the rectangle trick only works in the open event, if you have it in the shown then it gets JS errors. I have found like you that you get lots more JS errors if you put things in shown rather than open events. I know this goes against what Norman has said but I have seen the same as you.

You can’t imagine what it feels to read that. Cheers.

Regarding setting WebStyle, I’ve checked through my code and indeed I don’t set WebStyle neither in Open nor in Shown events so I didn’t stumbled on that issue yet. Perhaps this is a job for WebAnimator/WebTimer (I’ve found WebAnimator more robust for ‘delaying’ some actions, actualy). Perhaps what you can try is to use a WebTimer/Animator that you trigger from the [b]Open[b] event then in the WebTimer.Action event set your WebStyle. Try it first with very short delay like 250ms, 500ms, etc…

‘how it feels’ rather.