简体   繁体   English

在devexpress中的asp .net中多次调用客户端回调函数

[英]call multiple times client side callback function in asp .net in devexpress

How do I call multiple times client side callback function in asp .net in devexpress. 如何在devexpress中的asp .net中多次调用客户端回调函数。

Here is the pageload event: 这是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;
}

Here is the javascript function: 这是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>

Here only the single time call back occurs, but how can I call multiple times from multiple buttons? 这里只发生一次单次回叫,但是如何通过多个按钮多次回叫?

I am using devexpress along with asp .net c#. 我正在使用devexpress和asp .net c#。 Any suggestions regarding this problem? 关于这个问题有什么建议吗?

That looks like a simple function, not a callback itself, you can call that function from any Button this way 看起来像一个简单的函数,而不是回调本身,您可以通过任何方式从任何Button调用该函数

<dx:ASPxButton ID="btnOther" runat="server" Text="Function" AutoPostBack="false" 
                                      ClientSideEvents-Click="function(s, e) { InitiateCallBack(value); }">
                                  </dx:ASPxButton>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM