Click here to Skip to main content
13,045,019 members (40,045 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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
Posted 13-Apr-11 1:15am
Updated 13-Apr-11 1:18am
v3
Comments
Toniyo Jackson 13-Apr-11 7:18am
   
Added pre tag
Slacker007 13-Apr-11 7:30am
   
If you are going to go through the trouble of adding a <pre> tag then why don't you edit the grammar and spelling while you are at it. Just a thought.
Toniyo Jackson 13-Apr-11 7:34am
   
Yes. I will do it from next time. :)

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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;

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[^]
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 13 Apr 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100