用aspxcallback实现LABEL的动态刷新
我用了两个Callback一个用来启动刷新进程,一个用来动态显示进程信息。通过一个按钮启动调用第一个CallBack,又用了timer自动每500ms调用第二个CallBack, 但在IE调试总是报第二个的Uncaught ReferenceError: myCallback2 is not defined. 这个再三确认过,前台和后台都已定义过了,不知哪位大神能指点一下怎么回事。代码如下:客户端代码:<dxe:ASPxButton ID="ASPxButton1" runat="server" AutoPostBack="False" ClientInstanceName="mybutton"
Text="ASPxButton">
<ClientSideEvents Click="function(s, e) {
s.SetEnabled(false);
myLabel.SetText('Process completion: 0% ');
myLabel.SetClientVisible(true);
myTimer.SetEnabled(true);
myCallback1.PerformCallback();
}" />
</dxe:ASPxButton>
<dxcb:ASPxCallback ID="ASPxCallback1" runat="server"
ClientInstanceName="myCallback1">
<ClientSideEvents CallbackComplete="function(s, e) {
myButton.SetEnabled(true);
myTimer.SetEnabled(false);
myLabel.SetText('Process completed');
}" />
</dxcb:ASPxCallback>
<dxcb:ASPxCallback ID="ASPxCallback2" runat="server"
ClientInstanceName="myCallback3">
<ClientSideEvents CallbackComplete="function(s, e) {
var labelText = myLabel.GetText();
if(labelText != 'Process completed'){
myLabel.SetText('Process completion: ' + e.result + ' ');
}" />
</dxcb:ASPxCallback>
<dxt:ASPxTimer ID="ASPxTimer1" runat="server" Interval="500">
<ClientSideEvents Tick="function(s, e) {
myCallback3.PerformCallback();
}" />
</dxt:ASPxTimer>
<dxe:ASPxLabel ID="ASPxLabel1" runat="server" Text="测试"
ClientInstanceName="myLabel" ClientVisible="False" >
</dxe:ASPxLabel>
C#服务端代码
public partial class progress : System.Web.UI.Page
{
private static int pro;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack && !IsCallback)
{
pro = 0;
}
}
protected void ASPxCallback1_Callback(object source, DevExpress.Web.CallbackEventArgs e)
{
for (int i = 0; i < 10; i++)
{
pro = i;
System.Threading.Thread.Sleep(1000);
}
}
protected void ASPxCallback2_Callback(object source, DevExpress.Web.CallbackEventArgs e)
{
e.Result = pro.ToString();
}
页:
[1]