我有一個jquery datepicker控件。使用我想創建一個自定義ASP.net控件。 JQuery datepicker在顯示之前有一個屬性。該屬性是函數的類型。 在ASP.Net cotrol,我試圖通過JSonItem設置使用函數的字符串類型如下:如何在使用JSON的jQuery控件中設置類型函數的屬性?
StringBuilder strFunction = new StringBuilder();
strFunction.AppendLine(@"function (input) { ");
strFunction.AppendLine(@" setTimeout(function() { ");
strFunction.Append(@" var buttonPane = $(""#" + ClientID);
strFunction.Append(@""")");
strFunction.AppendLine(@".datepicker(""widget"").find("".ui-datepicker-close"").click(function() {");
strFunction.Append(@" $.datepicker.clearDate($(""#" + ClientID);
strFunction.AppendLine(@"""));");
strFunction.AppendLine(@" });");
strFunction.AppendLine(@" }, 1);");
strFunction.AppendLine("}");
textInput.Call("datepicker", Js.Json(
Js.JsonItem("onSelect", Js.Function(delegate {
if (ValueSelected != null) {
var request = CreateMethodInvocationRequest("OnSelect");
request.Send();
}
})
),
//This is the function type of property
Js.JsonItem("beforeShow",strFunction.ToString())
));
在這裏,但我沒有得到結果。運行時JScript錯誤被拋出。如果我沒有設置beforeShow屬性,那麼一切工作正常。但我需要這個屬性。任何人都可以建議其他方法
嗨Vinoth Babu,它不是beforeShow屬性的問題。這是strFunction.ToString()的問題。我們不能將該函數作爲字符串傳遞。這是我的問題。如何傳遞函數? – techfun
你把StringBuilder聲明爲「var StringBuilder」????? –
嗨Vinoth Babu。謝謝。是。我試過了。它沒有幫助。 – techfun