如何在devexpress中的asp .net中多次调用客户端回调函数。
这是pageload事件:
protected void Page_Load(object sender, EventArgs e)
{
if (Page.IsCallback)
return;
//Creating a reference of Client side Method, that is called after callback on server
String cbReference = Page.ClientScript.GetCallbackEventReference(this, "arg","ReceiveServerData", "");
//Putting the reference in the method that will initiate Callback
String callbackScript = "function CallServer(arg, context) {" +cbReference + "; }";
//Registering the method
Page.ClientScript.RegisterClientScriptBlock(this.GetType(),"CallServer", callbackScript, true);
}
public void RaiseCallbackEvent(String eventArgument)
{
DateTime dob = Convert.ToDateTime(eventArgument);
DateTime Today = DateTime.Now;
TimeSpan ts = Today - dob;
DateTime Age = DateTime.MinValue + ts;
int Years = Age.Year - 1;
int Months = Age.Month - 1;
int Days = Age.Day - 1;
result = Years.ToString();
}
public string GetCallbackResult()
{
return result;
}
这是javascript函数:
<script language="javascript" type="text/javascript">
function InitiateCallBack(value) {
CallServer(value, '');
}
// Called after the server side processing is done
function ReceiveServerData(arg, context) {
$("#MainContent_ASPxtxtAge_I").val(arg);
}
</script>
此处只进行单次回拨,但如何从多个按钮多次调用?
我正在使用devexpress和asp .net c#。 有关这个问题的任何建议吗?
答案 0 :(得分:0)
这看起来像一个简单的函数,而不是回调本身,你可以通过这种方式从任何Button调用该函数
<dx:ASPxButton ID="btnOther" runat="server" Text="Function" AutoPostBack="false"
ClientSideEvents-Click="function(s, e) { InitiateCallBack(value); }">
</dx:ASPxButton>