检查是否更改了在aspx.vb页面中定义的变量值的java脚本? [英] java script to check whether a variable value which is defined in aspx.vb page is changed or not?

查看:119
本文介绍了检查是否更改了在aspx.vb页面中定义的变量值的java脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我的Java脚本功能有2个问题.

问题1)
我可以从页面加载块或某些按钮事件中调用Java脚本.但是我需要知道是否有可能从计时器事件代码块中调用Java脚本函数.
我的意思是...我在更新面板中有一个计时器.
onTick ="timer1_event''

子timer1_event()
{
.....
如果(条件)则

//在这里,我需要为警报消息调用Java脚本函数.(并且我已经在aspx页面中定义了该函数)

如果
结束
结束子


问题2)

我在aspx.vb页面中定义了一个全局布尔变量.我正在尝试在aspx页面中定义的Java脚本函数中使用该变量.我在Java脚本函数中通过<%=变量%>调用了该变量.该变量的值将随不同事件而变化,例如在页面加载中,其值为FALSE.如果按下任何按钮,其值将更改为TRUE.
我的问题是,当我在使用此aspx.vb变量的pageload中调用Java脚本函数时,它正在使用该变量的初始值.但是,当某个事件改变其值时,该改变后的值将不会反映在Java脚本函数中.因此,如何在Java脚本函数中检查变量的值是否已更改.

我已经为这两个问题进行了足够的搜索,但并没有找到任何合适的解决方法.




在此先感谢.

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.

推荐答案

似乎您没有完全掌握客户端和服务器端代码之间的区别.

1)您可以在Sever端方法中执行JavaScript函数.前者在客户端处理,后者在服务器上处理.您可以使用诸如ClientScriptManager.RegisterClientScriptBlock之类的方法将JavaScript注入页面,但仅在处理了服务器端事件并将页面再次呈现给客户端之后才会执行. JavaScript具有计时器, setInterval [ setTimeout [ ^ ]

2)您可以使用隐藏元素来存储此值,以便可以在服务器上对其进行更新(必须使用runat ="server")并可以从JavaScript进行访问.
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.


这篇关于检查是否更改了在aspx.vb页面中定义的变量值的java脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆