Create Client Event Hander on Server

Answered (Verified) This post has 1 verified answer and 5 replies

Top 50 Contributor
Posts: 103
ladams Posted: Thu Oct 29, 2009 @ 4:55 PM

Is there any information out there on creating client event handlers on the server?  For instance I would like to create the callback's error eventhandler on the server so that I can bind application information and alertbox text based on server side configuration data.  I know I could call a serivice to return that information but seems like a bit much for an error message.  There used to be a ClientsideOnCallbackError Property, I see the property still works when set clientside but not avail. server side...

Thanksl

Answered (Verified) Verified Answer

Top 10 Contributor
Posts: 6,014
Answered (Verified) stephen Posted: Wed Nov 25, 2009 @ 12:41 PM
Verified by ladams

Client events can be created on the server. Here's a very simple example:

 

 <input type="button" value="do it" onclick="Callback1.callback();" />
        <ComponentArt:CallBack runat="server" ID="Callback1" OnCallback="Callback1_Callback">
                <Content>
                    <asp:Label runat="server" ID="lbl" Text="Default"></asp:Label>
                </Content>
         </ComponentArt:CallBack>

 

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack || Callback1.IsCallback)
        {
            string script = "function myFunction() { alert ('before callback'); }";
            ClientScript.RegisterClientScriptBlock(this.GetType(), "mycustomscript", script, true);

            ClientEvent ce = new ClientEvent();
            ce.EventHandler = "myFunction";
            Callback1.ClientEvents.BeforeCallback = ce;
        }
    }

    protected void Callback1_Callback(object sender, ComponentArt.Web.UI.CallBackEventArgs e)
    {
        lbl.Text = "did it";
        lbl.RenderControl(e.Output);
    }

Stephen Hatcher, Developer Support Manager

All Replies

Top 10 Contributor
Posts: 6,014
Answered (Verified) stephen Posted: Wed Nov 25, 2009 @ 12:41 PM
Verified by ladams

Client events can be created on the server. Here's a very simple example:

 

 <input type="button" value="do it" onclick="Callback1.callback();" />
        <ComponentArt:CallBack runat="server" ID="Callback1" OnCallback="Callback1_Callback">
                <Content>
                    <asp:Label runat="server" ID="lbl" Text="Default"></asp:Label>
                </Content>
         </ComponentArt:CallBack>

 

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack || Callback1.IsCallback)
        {
            string script = "function myFunction() { alert ('before callback'); }";
            ClientScript.RegisterClientScriptBlock(this.GetType(), "mycustomscript", script, true);

            ClientEvent ce = new ClientEvent();
            ce.EventHandler = "myFunction";
            Callback1.ClientEvents.BeforeCallback = ce;
        }
    }

    protected void Callback1_Callback(object sender, ComponentArt.Web.UI.CallBackEventArgs e)
    {
        lbl.Text = "did it";
        lbl.RenderControl(e.Output);
    }

Stephen Hatcher, Developer Support Manager
Top 50 Contributor
Posts: 103
ladams Posted: Wed Nov 25, 2009 @ 1:16 PM

That is simple... thanks!

Top 10 Contributor
Posts: 6,014
stephen Posted: Mon Nov 30, 2009 @ 11:28 AM

No problem at all- glad I could help!

Stephen Hatcher, Developer Support Manager
Top 500 Contributor
Posts: 30
fiatgroup Posted: Sat Mar 13, 2010 @ 9:42 AM
Quite remarkably this is *exactly* what I'm looking for... and there it is on the front page of the Help Forums - brill!

Thanks

Ben
Top 10 Contributor
Posts: 6,014
stephen Posted: Thu Mar 18, 2010 @ 8:40 AM

Glad we could help!

Stephen Hatcher, Developer Support Manager
Page 1 of 1 (6 items)