0

I have a ComponentArt CallBack control. Client side, I want to perform a callback using javascript when the dropdown list is changed. In the javascript, I want to explicitly pass both the control and the associated ComponentArt.Web.UI.CallBackEventArgs.

Below is a bare bones implementation of what I'm trying to accomplish on a larger scale.

What do I put in the javascript to explicitly pass the ComponentArt.Web.UI.CallBackEventArg? Assuming this is possible, the part I'm interested in is marked WHAT_DO_I_PUT_HERE.

The ascx control contains:

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="foo.ascx.cs" Inherits="WebPlugins.foo" %>
<%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %>

<script language="javascript" type="text/javascript">
    function changeDDL(sender) {
        alert("This alert pops up. No problems here.");
        fooClbk.Callback(sender, WHAT_DO_I_PUT_HERE );
    }
</script>

<ComponentArt:CallBack id="fooClbk" runat="server" OnCallback="fooClbk_Callback">
    <Content>
        <asp:Label ID="lblmyDDL" AssociatedControlID="myDDL" runat="server" Text="Choose an option: "></asp:Label>
        <br />
        <asp:DropDownList ID="myDDL" runat="server">
            <asp:ListItem Value="DEFAULT" Text="The Default Value"></asp:ListItem>
            <asp:ListItem Value="ONE" Text="First!"></asp:ListItem>
            <asp:ListItem Value="TWO" Text="Runner up"></asp:ListItem>
        </asp:DropDownList>
    </Content>
    <LoadingPanelClientTemplate>
        <p>Refreshing Rate Information...</p>
    </LoadingPanelClientTemplate>
</ComponentArt:CallBack>

The ascx.cs codebehind contains:

//Some includes...

namespace WebPlugins
{
    public partial class foo : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            initializeDDLEvt();
            //Initialize some other stuff...
        }

        private void initializeDDLEvt()
        {
            /* Register client events for DDL */
            myDDL.Attributes.Add("onChange", "changeDDL(this);");
        }

        protected void fooClbk_Callback(object sender, ComponentArt.Web.UI.CallBackEventArgs e)
        {
            //Render some new HTML using the ComponentArt.Web.UI.CallBackEventArgs
        }
    }
}

EDIT: My basic understanding of what was going on here was wrong. I've provided some detail into where I went wrong in a comment below. Thanks @jalpesh for the componentart forum link. This pointed me in the direction I needed to go.

Peach
  • 2,687
  • 4
  • 23
  • 26
  • I don't think i understand your question. What are you attempting to do with the callback method? –  Nov 25 '10 at 20:32
  • @Sergey I'm trying to do something that I can't do... I'll follow up with a detailed comment. – Peach Nov 25 '10 at 20:42

1 Answers1

0

The quick answer to this question: It can't be done exactly how the question's phrased.

In more detail:

The assumption is, the javascript function explicitly passes the sender and event arguments on callback. This is not the case. Instead, the javascript function is passing some parameters that are bundled up into the event arguments.

The sender (in this case a dropdownlist control) and the CallBackEventArgs are implicitly passed to the fooClbk_Callback method. I think this is partly a misunderstanding of the difference between functions and methods.

Basically, this:

function changeDDL(sender) {
    alert("This alert pops up. No problems here.");
    fooClbk.Callback(sender, WHAT_DO_I_PUT_HERE );
}

should actually be something like this:

function changeDDL(aControl) {
    alert("This alert pops up. No problems here.");
    fooClbk.Callback(aControl.options[aControl.selectedIndex].value); // Or whatever other params
}

The params passed in from the javascript function can be accessed within the callback method like this:

protected void fooClbk_Callback(object sender, ComponentArt.Web.UI.CallBackEventArgs e)
{
    //Do Some stuff
    string myVal = e.Parameters[0];
    // Do something with the chosen myVal.
}
Community
  • 1
  • 1
Peach
  • 2,687
  • 4
  • 23
  • 26