Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello every one,

I am having 2 problems with Java script function.

Q 1)
I am able to call a java script from page load block or some button event. But I need to know whether is there any possibility to call a java script function from timer event code block.
what I mean to say is... I am having a timer in an update panel.
onTick='timer1_event'

Sub timer1_event()
{
.....
if (condition) then

// here i need to call a java script function for an alert message..(and i have defined that function in aspx page)

end if

End Sub


Q 2)

I have defined a global Boolean variable in aspx.vb page. I am trying to use that variable in java script function defined in aspx page. I called that variable in java script function by <%= variable %>. That variable's value will be change on different events.For example in page load its value will be FALSE. If any button is pressed its value will be changed to TRUE.
My problem is , when I am calling the java script function in pageload, which uses this aspx.vb variable , it is taking the initial value of that variable. But when its value is changed up on some event,that changed value is not reflecting in the java script function. So how to check whether the value of the variable is changed or not in java script function.

I have searched enough for solution to these two question but dint find any appropriate one.




Thanks in Advance.
Posted

1 solution

It seems you don't fully grasp the difference between client-side and server-side code.

1) You execute a JavaScript function within a Sever-side method. The former is processed at the client, the latter on the server. You can use methods such as ClientScriptManager.RegisterClientScriptBlock to inject JavaScript into the page but it will only execute AFTER the server-side event has been handled and the page rendered to the client again. JavaScript have timers, setInterval[^] or setTimeout[^]

2) You can use a hidden element to store this value so it can be updated on the server (must use runat='server') and accessible from JavaScript.
 
Share this answer
 
Comments
Naveen_143 8-Apr-12 6:41am    
Hello Mark,
Thanks for your reply.
In your answer to my first question,you said ,java script will only execute AFTER the server-side event has been handled , but I am handling the the TIMER in timer1_event. have already tried ClientScriptManager.RegisterClientScriptBlock but it is not executing the java-script function. Can you give more explanation on this about java script.

And for my 2nd question,I will try hidden variables as you said.
Naveen_143 11-Apr-12 2:31am    
Thanks Mark, with your sugession to use hidden field, I managed to complete my task.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900