本文介绍了ASP.NET 3.5中的icallbackeventHandler的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习ICallbackEventHandler.
所以为此,我在aspx页面中使用了标签和按钮服务器控件.
如下所示

hi i am trying to learn ICallbackEventHandler.
so for this i took label and button server control in aspx page.
like as follows

<head  runat="server">
    <title></title>
    <script type="text/javascript">
        function scriptevent(result, context) {

            if (document.getElementById("lbl") != null) {
                document.getElementById("lbl").value = result;
            }

        }

    </script>
</head>
<body>
    <form id="form1"  runat="server">
    <div>

    <label id="lbl"  runat="server"></label>
    <asp:Button ID="bttn" Text="print" runat="server"  />
    </div>
    </form>
</body>


我在页面后面的代码是


and my code behind page is

public partial class testPag1e : System.Web.UI.Page, ICallbackEventHandler
    {
        protected string text=string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            string refscript = this.Page.ClientScript.GetCallbackEventReference(this, "", "scriptevent", null, true);
            bttn.Attributes["OnClick"] = refscript;

        }

        #region ICallbackEventHandler Members

        public string GetCallbackResult()
        {
            text = "sunny";
            return text;
        }

        public void RaiseCallbackEvent(string eventArgument)
        {
           // text = eventArgument;
        }

        #endregion
    }


当我单击按钮时,它没有将标签控件的文本属性设置为晴天"
有人可以帮我吗


when i click on button it doesnt set text property of label control to "sunny"
can anyone help me out

推荐答案

string refscript = this.Page.ClientScript.GetCallbackEventReference(this, "", "scriptevent", null, true);
            bttn.Attributes["OnClick"] = refscript;


在正确的.您需要向页面注册callbackevent参考.

看一下这个MSDN示例:客户端回调实现(C#)示例 [ ^ ]
MSDN:另一个详细说明 [ ^ ]

此外,请看一下带有样本的本文.它可以帮助您更深入地学习: Web应用程序的ClientCallback自定义控件 [ ^ ]


In correct. You need to register the callbackevent refernece with page.

Have a look at this MSDN example: Client-Callback Implementation (C#) Example[^]
MSDN: Another detailed explanation[^]

Further, have a look at this article with sample. It would help you to dig deeper and learn: ClientCallback custom control for web applications[^]


这篇关于ASP.NET 3.5中的icallbackeventHandler的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 11:27