Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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
Edited 13-Apr-11 1:18am
v3
Comments
Toniyo Jackson at 13-Apr-11 7:18am
   
Added pre tag
Slacker007 at 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 at 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
0 Sergey Alexandrovich Kryukov 353
1 OriginalGriff 304
2 George Jonsson 258
3 Shemeemsha RA 138
4 Animesh Datta 130
0 OriginalGriff 5,985
1 Sergey Alexandrovich Kryukov 5,341
2 CPallini 4,760
3 George Jonsson 3,400
4 Gihan Liyanage 2,522


Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 13 Apr 2011
Copyright © CodeProject, 1999-2014
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