how to access a value from classlibrary .cs file into a javascript file

Posted by Ragha under C# on 10/19/2008 | Views : 7333 | Status : [Member] | Replies : 3
hello,

in my solution i have two projects

like one is classlibrary project in which there are only .js files and in scripts folder i have .js files

another is a web application

i would like to access a value from .cs file into .js file

how can i do this?

i have tried with sessions but failes, i have also tried with static variables but failed

please suggest some solutions

any help would be appreciated

regards,
sudha




Responses

Posted by: Raja on: 10/19/2008 [Member] Starter

Up
0
Down
Hey Sudha,

you can do that using session too, Just set the session into your .cs file and in the .aspx page write like this.

<script language="javascript">
var yourVariable = '<%= Session["YourSession"].ToString() %>'
</script>

Here your value will be in JavaScript variable called yourValue and you can use that variable in any javascript file on the page.

Alternatively, if you can return the value using some function and store into some protected or public variable and print on the .aspx page as described above or even you can set the value into cookie and print cookie value on the .aspx page in the same way.

Hope this help.

Thanks

Regards,
Raja, USA

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ragha on: 10/20/2008 [Member] Starter

Up
0
Down
hi Raja,
thanks for your immediate response to my question

but you didnt understood my question properly

the question is not .aspx file

i would like to use the value into pure javascript file(.js file) not an inline javascript code

regards,
sudha



Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Raja on: 10/20/2008 [Member] Starter

Up
0
Down
Dear I am not sure about .js file but try, I think you should be able to get the javascript variable value of .aspx page intto your .js file. Otherwise you may need to place your function in .js file to .aspx page.

Thanks

Regards,
Raja, USA

Ragha, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response