hai friends,

i want to access the asp.net variable in the javascript.

ie i want to access the field that was displayed in the asp.net pages will be accessed in javascript.

real problem is,

my project is online examination there i am using duration for the exam which is stored the database, the field is reterived and viewed in one form.

no i want to display the time and set the alert message to the student that ur time is over.

for that i want duration variable to be accessed in javascript.

Got the problem,
plz help me.

10 Years
Discussion Span
Last Post by muthu

in the aspx page do this. Can't remember how to do timers off the top of my head but you should be able to get the point.

<script language=java>
alert('<% writeDuration();%>')

and then in the code behind put this function

public void writeDuration(){
int duration;
// get the duration from the database then




thanks for ur immediate reply. i will check and then tell.


The best way is to use an HTML control instead of Web control
use text filed from HTML tab instead of TextBox in Web Controls Tab
and then right click on it -> run as server control .
then you can use it as a server control (in asp.net) and as an html control in javascript.
You can get it in javascript by document.formname.fieldname
where formname is the form name , and field name is the name of the text filed you created.
and user settimeout(func,1000) which execute the func every 1 second and display the time in the text field through the defintion of the func.


hai friend,

thanks for ur immediate reply, i did it and it's working, but it has one problem i give the duration for the full exam, but it takes the time for one question and after clicking the next button it takes the whole duration and did it again, please reply these message.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.