是否可以在Scriptcontrol中绑定客户端和服务器端的属性,这样当我在javascript中设置属性时,更改也将在后台代码中可见,当我在后台代码中设置属性时,更改将在javascript中可见?
我不能让它像上面那样工作-它是最初设置的,当我在声明scriptcontrol的地方设置属性时,但当我稍后更改它时,它仍然和以前一样……
编辑:我尝试为我们的ASP.NET应用程序中的长回发做一个ProgressBar。我已经尝试了很多选择,但没有一个对我有效。我想在后面的代码中设置进度值,并在长任务回发期间在视图中更新它。
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:
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();我非常感谢任何实现这个进度条的方式……
发布于 2012-05-14 15:47:01
就我个人而言,我经常使用隐藏字段。请记住,隐藏字段是不安全的,并且可能有其他缺陷,因为它们实际上并不隐藏它们的值,只是不显示它。
ASPX标记
<asp:HiddenField ID="hiddenRequest" runat="server" ClientIDMode="Static" />背后的ASPX.CS代码
public string HiddenRequest
{
set
{
hiddenRequest.Value = value;
}
get
{
return hiddenRequest.Value;
}
}页面JAVASCRIPT (使用jQuery)
$('#hiddenRequest').val('MyResult');这样,我就可以使用一个变量访问相同的字段,从客户端和服务器端都可以访问。
https://stackoverflow.com/questions/10579248
复制相似问题