ScriptControl的 - 绑定客户端和放大器;服务器属性 [英] Scriptcontrol - bind client & server properties

查看:157
本文介绍了ScriptControl的 - 绑定客户端和放大器;服务器属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以绑定在ScriptControl的客户端和服务器端的性能,所以当我在JavaScript中设置属性,改变将在后面code也看到,当我设置code属性背后,变化将在JavaScript可见?

Is it possible to bind properties on the client and server side in Scriptcontrol, so when I set property in javascript, change will be visible also in code behind and when I set property in code behind, change will be visible in javascript?

我不能让它像上面的工作 - 它设置最初,当我设置的地方ScriptControl的声明属性,但是当我后来改变它仍然和以前一样...

I can't get it work like above - it is set initially, when I set property where scriptcontrol is declared, but when I change it later it is still the same as before...

编辑:我试图为我们的ASP.NET应用程序长回传做一个进度条。我已经尝试了许多选择,但没有对我的作品......我想设置在后面code进度值并已考虑到长期的任务回发期间更新。

I try to do a ProgressBar for long postbacks in our ASP.NET application. I have tried many options but none works for me... I want to set progress value in code behind and has it updated in view during long task postback.

code表示ScriptControl的:
C#中:

Code for ScriptControl: C#:

public class ProgressBar : ScriptControl
{
    private const string ProgressBarType = "ProgressBarNamespace.ProgressBar";
    public int Value { get; set; }
    public int Maximum { get; set; }

    protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors()
    {
        this.Value = 100;
        this.Maximum = 90;
        var descriptor = new ScriptControlDescriptor(ProgressBarType, this.ClientID);

        descriptor.AddProperty("value", this.Value);
        descriptor.AddProperty("maximum", this.Maximum);

        yield return descriptor;
    }

    protected override IEnumerable<ScriptReference> GetScriptReferences()
    {
        yield return new ScriptReference("ProgressBar.cs.js");          
    }
}

使用Javascript:

Javascript:

Type.registerNamespace("ProgressBarNamespace");

ProgressBarNamespace.ProgressBar = function(element) {
    ProgressBarNamespace.ProgressBar.initializeBase(this, [element]);
    this._value = 0;
    this._maximum = 100;
};

ProgressBarNamespace.ProgressBar.prototype = {
    initialize: function () {
        ProgressBarNamespace.ProgressBar.callBaseMethod(this, "initialize");
        this._element.Value = this._value;
        this._element.Maximum = this._maximum;

        this._element.show = function () {
            alert(this.Value);
        };
    },
    dispose: function () {
        ProgressBarNamespace.ProgressBar.callBaseMethod(this, "dispose");
    },
    get_value: function () {
        return this._value;
    },
    set_value: function (value) {
        if (this._value !== value) {
            this._value = value;
            this.raisePropertyChanged("value");
        }
    },
    get_maximum: function () {
        return this._maximum;
    },
    set_maximum: function (value) {
        if (this._maximum !== value) {
            this._maximum = value;
            this.raisePropertyChanged("maximum");
        }
    }
};

ProgressBarNamespace.ProgressBar.registerClass("ProgressBarNamespace.ProgressBar", Sys.UI.Control);
if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();

我将AP preciate任何方式来实现这个进度条...

I'll appreciate any way to implement this progress bar...

推荐答案

就个人而言,我经常这样使用隐藏域。
请记住,隐藏域是不安全的,可能有其他的挫折,因为它们实际上并不掩饰自己的价值,就根本不显示它。

Personally, I do this often using hidden fields. Bear in mind that hidden fields are not secure and may have other downfalls, since they don't actually hide their value, just simply do not display it.

ASPX标记

<asp:HiddenField ID="hiddenRequest" runat="server" ClientIDMode="Static" />

ASPX.CS code后面

ASPX.CS Code behind

    public string HiddenRequest
    {
        set
        {
            hiddenRequest.Value = value;
        }
        get
        {
            return hiddenRequest.Value;
        }
    }

页JAVASCRIPT(使用jQuery)

Page JAVASCRIPT (with jQuery)

$('#hiddenRequest').val('MyResult');

这样的话,我可以访问使用一个变量作为同一领域如此,无论从客户端和服务器端进行访问。

This way, I can access the same field using one variable as such, accessed both from client side and server side.

这篇关于ScriptControl的 - 绑定客户端和放大器;服务器属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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