[英]Scriptcontrol - bind client & server properties
是否可以在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();
我將不勝感激以任何方式實現此進度條...
我個人經常使用隱藏字段來執行此操作。 請記住,隱藏字段並不安全,並且可能還會有其他問題,因為它們實際上並未隱藏其價值,只是根本不顯示它。
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');
這樣,我可以使用從客戶端和服務器端訪問的一個變量來訪問同一字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.