CodeCharge Studio
search Register Login  

Visual PHP Web Development

Visually Create Internationalized Web Applications, Web Reports, Calendars, and more.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> ASP

 Session variable and javascript

Print topic Send  topic

Author Message
SIGEAL

Posts: 14
Posted: 01/28/2004, 1:34 AM

Hi,

Is it possible to get a session variable using javascript ? What is the code for that ?

What I want to do is enabling/disabling a listbox depending on the user login id/name/group.

Thanks for your help.
_________________
Christophe DAMOUR - SIGéal
View profile  Send private message
peterr


Posts: 5971
Posted: 01/28/2004, 1:47 AM

Yes, you can create a Label and then replace it with JavaScript that will create a JavaScript variable containing your session. For example:
Label1.Value = "<script language=""Javascript"">var Mysession = " & Session("UserID") & ";</script>"
(also set Label's "Content" property to HTML)

Now you will have a JavaScript variable "Mysession" that contains your UserID session.
_________________
Peter R.
YesSoftware Forums Moderator
For product support please visit http://support.yessoftware.com
View profile  Send private message
Edd


Posts: 547
Posted: 01/28/2004, 1:50 AM

SIGEAL

Sessions are accessable at the Server - Javascript in ASP is used at the client.

You can write ASP Server code that can output the Javascript function OR a variable that you can test with your Javascript.


_________________
Accepting and instigating change are life's challenges.

http://www.syntech.com.au
View profile  Send private message
DonB
Posted: 01/28/2004, 5:27 AM

As you have found, the login information is stored in a session variable.
You need to inspect these values and change the Listbox to be disabled based
on these values.

I have written an article showing how you do this. It is available here:
http://www.gotodon.com/ccbth/Features/Knowledgebase.asp?find=disable
--
DonB

http://www.gotodon.com/ccbth


"SIGEAL" <SIGEAL@forum.codecharge> wrote in message
news:640178234abb63@news.codecharge.com...
> Hi,
>
> Is it possible to get a session variable using javascript ? What is the
code for that ?
>
> What I want to do is enabling/disabling a listbox depending on the user
login id/name/group.
>
> Thanks for your help.
> _________________
> Christophe DAMOUR - SIGéal
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

SIGEAL

Posts: 14
Posted: 01/30/2004, 12:48 AM

Hi,

Thank you for your helpfull answers.

Peterr : I tried your solution and it works fine. Thanks again.

DonB : I tried your solution too, but I had the following problem :
When I move {LabelDisable} to put it in the <SELECT... > statement, CCS informs me that it can't find the LabelDisable control in HTML and asks me if I want to delete it. If I answer Yes, the custom code BeforeShow is commented, if I answer No, it seems to work, but the listbox isn't disabled...
What am I missing ?

_________________
Christophe DAMOUR - SIGéal
View profile  Send private message
DonB
Posted: 01/30/2004, 6:27 AM

This sounds like the Label was created within a different "template block".
Since CCS processes the template a block at a time, the Label is not seen
where it should be and so the warning appears.

Sometimes the placement of the {xyz} label matters to CCS. I have been able
move it to right before the "> (last item in the html tag) and solve the
problem. I guess CCS fails to properly parse template tags when they appear
as attributes, under certain conditions.

If you repeat the steps, check that there are no <!-- bla bla --> markers
between where you create the label and where you move it to. These indicate
boundaries for the template blocks and you can't move the label across those
boundaries. This can easily happen to you when you are working with a grid
because there are several nested blocks within the grid control.

If you care to post the relevant section of HTML (after creating the label
but before moving it) I'll take a look at it to see what might be wrong with
it.

--
DonB

http://www.gotodon.com/ccbth


"SIGEAL" <SIGEAL@forum.codecharge> wrote in message
news:6401a1a78a238f@news.codecharge.com...
> Hi,
>
> Thank you for your helpfull answers.
>
> Peterr : I tried your solution and it works fine. Thanks again.
>
> DonB : I tried your solution too, but I had the following problem :
> When I move {LabelDisable} to put it in the <SELECT... > statement, CCS
informs me that it can't find the LabelDisable control in HTML and asks me
if I want to delete it. If I answer Yes, the custom code BeforeShow is
commented, if I answer No, it seems to work, but the listbox isn't
disabled...
> What am I missing ?
>
> _________________
> Christophe DAMOUR - SIGéal
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

SIGEAL

Posts: 14
Posted: 02/02/2004, 11:49 PM

DonB,

Here is the HTML after I added the label :

<tr>
<td class="SOFA_V4FieldCaptionTD">Avis CD/CS </td>
<td class="SOFA_V4DataTD">
<select name="{AVIS1_Name}" class="SOFA_V4Select">
<option value="" selected></option>
{AVIS1_Options}
</select>
{Label1} </td>
<td class="SOFA_V4FieldCaptionTD"> Motif refus</td>
<td class="SOFA_V4DataTD">
<select class="SOFA_V4Select" name="{MOTIF1_Name}">
<option value="" selected></option>
{MOTIF1_Options}
</select>
</td>
</tr>

Where {AVIS1_Options} is the listbox I am trying to disable.

I tried another handsome solution :
var group;
group=<%=CCGetGroupID()%>; or group=<%=Session("GROUP_SOFA")%>;

But it didn't work... Have you got a clue ?

Thanks again.
_________________
Christophe DAMOUR - SIGéal
View profile  Send private message
DonB
Posted: 02/03/2004, 6:19 AM

I changed the HTML (moved the label):

<tr>
<td class="SOFA_V4FieldCaptionTD">Avis CD/CS </td>
<td class="SOFA_V4DataTD">
<select name="{AVIS1_Name}" class="SOFA_V4Select" {Label1}>
<option value="" selected></option>
{AVIS1_Options}
</select>
</td>
<td class="SOFA_V4FieldCaptionTD"> Motif refus</td>
<td class="SOFA_V4DataTD">
<select class="SOFA_V4Select" name="{MOTIF1_Name}">
<option value="" selected></option>
{MOTIF1_Options}
</select>
</td>
</tr>

This is what I used to test it here. This should work for you. I put a
Before Show event on Label1 and added this code. CCGetUserID() returns "0"
if the user is not logged-in:

If CCGetUserID() = 0 Then
' no session variable, so disable the listbox
Eventcaller.Value = "DISABLED"
Else
' user is logged in, enable the listbox
Eventcaller.Value = ""
End If


On the embedded <%...%>: This will not work because the HTML is read in by
the main ASP page, not executed/interpreted by the web server. So, embedded
script will not be handled as script, just as text.
--
DonB

http://www.gotodon.com/ccbth


"SIGEAL" <SIGEAL@forum.codecharge> wrote in message
news:6401f529dea2fb@news.codecharge.com...
> DonB,
>
> Here is the HTML after I added the label :
>
> <tr>
> <td class="SOFA_V4FieldCaptionTD">Avis CD/CS </td>
> <td class="SOFA_V4DataTD">
> <select name="{AVIS1_Name}" class="SOFA_V4Select">
> <option value="" selected></option>
> {AVIS1_Options}
> </select>
> {Label1} </td>
> <td class="SOFA_V4FieldCaptionTD"> Motif refus</td>
> <td class="SOFA_V4DataTD">
> <select class="SOFA_V4Select" name="{MOTIF1_Name}">
> <option value="" selected></option>
> {MOTIF1_Options}
> </select>
> </td>
> </tr>
>
> Where {AVIS1_Options} is the listbox I am trying to disable.
>
> I tried another handsome solution :
> var group;
> group=<%=CCGetGroupID()%>; or group=<%=Session("GROUP_SOFA")%>;
>
> But it didn't work... Have you got a clue ?
>
> Thanks again.
> _________________
> Christophe DAMOUR - SIGéal
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>


Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Internet Database

Visually create Web enabled database applications in minutes.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.