ASP.NET 3.5中的icallbackeventHandler [英] icallbackeventHandler in asp.net 3.5

查看:68
本文介绍了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

推荐答案

您尝试调试并查看执行情况吗?
您尚未在此处进行回调期间处理所需的操作.

这不是这样做的方法:
Did you try to debug and see how the execution went?
You have not handled the operations required during the callback out here.

This is not the way to do it:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆