Click here to Skip to main content
12,550,348 members (44,376 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB Javascript VB.NET
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.

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 7-Apr-12 8:20am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
KNK143 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.
KNK143 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

Advertise | Privacy | Mobile
Web01 | 2.8.161021.1 | Last Updated 7 Apr 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100