andrewi
Posts: 162
|
Posted: 06/01/2004, 10:29 AM |
|
I'm trying to set the value of a label in a Header page using the Before Show event. This code works fine when the page is not includable:
Function Header2_BeforeShow() 'Header2_BeforeShow @1-23E7CB02
if (CCGetUserID = "") then
lblMenu0.Value = "Login"
else
lblMenu0.Value = "Logout: " + CCGetUserID()
end if
End Function 'Close Header2_BeforeShow @1-54C34B28
But on changing to an includable page, the code fails. Variable lblMenu0 is undefined.
in http://forums.codecharge.com/posts.php?post_id=42670&s_...=events+include it is suggested that, because events are different in included pages, the page name should be added to the label reference.
I've tried Header2.lblMenu0.Value...
and Header2.HTMLTemplate.Block( ... etc as Nicole suggested.
In each case the error is that Header2 is undefined.
Can anyone help: how can I set the value of a label in a Header/Footer by code?
Thanks.
|
|
|
peterr
Posts: 5971
|
Posted: 06/01/2004, 12:47 PM |
|
I just tested this and worked OK for me. I used:
Header.Label1.Value = "abc"
Possibly try deleting your event completely and recreate it, in case something got corrupted. Maybe also create a new includable page Header3 for testing, use simlpe code as the one I did, and if it works OK then compare both pages and investigate details.
I'm not sure what else could be wrong, unless someone else has additional ideas.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
DonB
|
Posted: 06/01/2004, 1:37 PM |
|
I always use the "Eventcaller" object, which should prevent this sort of
problem from occurring. I think you will find that
Header2.lblMenu0.Value = "Login" works
but I'd have coded it as
Eventcaller.lblMenu0.Value = "Login"
or (my personal preference) put the code into the Label's Before Show event
rather than the Include object:
Eventcaller.Value = "Login"
By using Eventcaller, you should find your code works when it's included or
when it's not included. This also ensures your code continues to work even
when you rename the parent object (i.e., "Header2")
(note to non-ASP users who might read this: you don't have the Eventcaller
object available to you)
--
DonB
http://www.gotodon.com/ccbth
|
|
|
andrewi
Posts: 162
|
Posted: 06/01/2004, 1:51 PM |
|
Thanks Peter - that's solved it.
Header.Label1.Value = "abc" works.
Because the Header page was actually called Header2.ccp, I was using Header2.Label1.Value = "abc"
The instructions in the other thread were to use the Page name - but strictly, they should be to use the the name of the 'include Page' object on the page it's included in.
Interestingly, this means that the code on the included page is actually dependent on the name given to the included object in the main page. That's normally no problem with Headers, since normally the include object is generally called 'Header'. But it could catch you out with other types of included pages if you don't name the include object consistently.
Thanks again for the valued help.
|
|
|
peterr
Posts: 5971
|
Posted: 06/01/2004, 2:09 PM |
|
andrewi,
Good point, I didn't think about this and I agree that there is a potential for mistake.
The EventCaller method proposed by Don should also be good. It is rather an internal feature and our developers advised me that it may not be consistent with some current or future components, but in practice it seems to work well.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com |
|
|
DonB
|
Posted: 06/01/2004, 5:29 PM |
|
Peter,
I hope that is not the case. Tech support always steered us (well, me
anyway) towards it's use. And I find it very handy to do a "With
Eventcaller" block in my code - shortens the typing necessary quite a bit as
well as the "name-independent" code it facilitates.
--
DonB
http://www.gotodon.com/ccbth
"peterr" <peterr@forum.codecharge> wrote in message
news:640bcf0a3b5239@news.codecharge.com...
>
> The EventCaller method proposed by Don should also be good. It is rather
an
> internal feature and our developers advised me that it may not be
consistent
> with some current or future components, but in practice it seems to work
well.
> _________________
> Peter R.
|
|
|
andrewi
Posts: 162
|
Posted: 06/02/2004, 12:43 AM |
|
DonB, thanks very much for the information. If you can rely on Eventcaller it sounds a useful solution.
|
|
|
|