Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
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

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[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900