jsherk
Posts: 34
|
| Posted: 01/26/2009, 3:32 PM |
|
I have come across the following issue when using $Tpl with a Label, where it does not display the setvar text assigned to it if you insert the label from the toolbox. Anybody else seen this problem??
How to recreate the problem:
1- Create a new project
2- Go to the Design Tab of NewPage1, and insert a Label on the page using the Toolbox->Forms->Label button. It should be called Label1.
3- Now go to the HTML tab of NewPage1 (not the toolbox tab, but the tab beside the design tab), and manually type in another label beside the first one called {Label2}. Do NOT use the toolbox to insert this second label.
4- Now in the BeforeShow event of NewPage1, add the following custom code:
//Custom Code @3-2A29BDB7
// -------------------------
global $Tpl;
$Tpl->setvar("Label1","testing1");
$Tpl->setvar("Label2","testing2");
// -------------------------
//End Custom Code
5- Now publish the page and notice that only the text for Label2 appears on the screen, but not for Label1.
Thanks
|
 |
 |
damian
Posts: 838
|
| Posted: 01/26/2009, 5:32 PM |
|
confirmed... (v4.1)
i also cant set it using:
$Component->$Label1->SetValue("testing1");
i can set it using:
$Component->SetValue("testing1");
on before show of label only....
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
jsherk
Posts: 34
|
| Posted: 01/26/2009, 7:00 PM |
|
I'm using 4.1.00.032 specifically.
|
 |
 |
damian
Posts: 838
|
| Posted: 01/26/2009, 9:18 PM |
|
likewise.
_________________
if you found this post useful take the time to help someone else.... :)
|
 |
 |
jsherk
Posts: 34
|
| Posted: 01/27/2009, 5:43 AM |
|
I sent an email to support last night, and they are looking into it.
|
 |
 |
jsherk
Posts: 34
|
| Posted: 01/28/2009, 6:33 AM |
|
Got the following back from support... I think they are saying that this is not a bug, but waiting for another reply back to confirm.
-----------------------------------------------------
FROM SUPPORT:
1. let me provide a brief explanation about CCS code execution order. After Before Show event of container (page in your case) the database values or Default Values are assigned to controls located in container (Label1 in your case). Controls' BeforeShow events are also fired after container's Before Show event.
So it appears that value is set to Label1 via SetVar() method but later it is replaced with Default Value value that is seems to be empty in your case.
2. the code
$Component->$Label1->SetValue("testing1");
does not work in label's Before Show event because in this event the $Component points to Label1 control. That's why the valid code is
$Component->SetValue("testing1");
Regards,
-------------------------------------------------------------
|
 |
 |
jsherk
Posts: 34
|
| Posted: 01/28/2009, 12:14 PM |
|
Okay, it appears that this is not bug, but is expected behaviour.
For a manually entered label (like {Label2} above), the $Tpl variable works fine to set it as shown here:
global $Tpl;
$Tpl->setvar("Label2","testing2");
In order to set Label1 though you need to use $Component like this:
$Component->Label1->setvalue("testing1");
Apparently the Default Value in the Label Data Properties will override the $Tpl variable, but will not override the $Component variable.
damian, the reason it did not work for you above was because of the $ in front of Label1.
Changing custom code in step 4 of original post above, to this, makes it work.
//Custom Code @3-2A29BDB7
// -------------------------
$Component->Label1->setvalue("testing1");
global $Tpl;
$Tpl->setvar("Label2","testing2");
// -------------------------
//End Custom Code
|
 |
 |
|