2012-12-14 23 views
0

我有一個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屬性,那麼一切工作正常。但我需要這個屬性。任何人都可以建議其他方法

回答

0

我解決了這個問題,使用一個函數返回解析字符串到JSExpression。

Js.JsonItem("beforeShow",strFunction.ToString()) 
0

用戶的一個從以下根據自己的需要,而不是beforeShow,

渲染, beforerender, AfterRender階段

我們不能使用beforeShow,因爲它只有當它被用來與被觸發顯示方法..

+0

嗨Vinoth Babu,它不是beforeShow屬性的問題。這是strFunction.ToString()的問題。我們不能將該函數作爲字符串傳遞。這是我的問題。如何傳遞函數? – techfun

+0

你把StringBuilder聲明爲「var StringBuilder」????? –

+0

嗨Vinoth Babu。謝謝。是。我試過了。它沒有幫助。 – techfun

相關問題