如何在回调时从 javascript 函数显式传递 ComponentArt CallBackEventArgs?
我有一个 ComponentArt CallBack 控件。客户端,我想在下拉列表更改时使用 JavaScript 执行回调。在 javascript 中,我想显式传递控件和关联的 ComponentArt.Web.UI.CallBackEventArgs。
下面是我试图在更大范围内完成的任务的简单实现。
我应该在 javascript 中放入什么来显式传递 ComponentArt.Web.UI.CallBackEventArg? 假设这是可能的,我感兴趣的部分被标记为 WHAT_DO_I_PUT_HERE。
ascx 控件包含:
<%@ 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>
ascx.cs 代码隐藏包含:
//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
}
}
}
编辑:我对这里发生的情况的基本理解是错误的。我在下面的评论中提供了一些关于我出错的地方的详细信息。感谢@jalpesh 提供的 componentart 论坛链接。这为我指明了我需要前进的方向。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这个问题的快速回答:不能完全按照问题的措辞来完成。
更详细地说:
假设 JavaScript 函数在回调时显式传递发送者和事件参数。事实并非如此。相反,JavaScript 函数会传递一些捆绑到事件参数中的参数。
发送者(在本例中为下拉列表控件)和 CallBackEventArgs 隐式传递给 fooClbk_Callback 方法。我认为这在一定程度上是对函数之间差异的误解和方法。
基本上,这:
实际上应该是这样的:
从 javascript 函数传入的参数可以在回调方法中访问,如下所示:
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:
should actually be something like this:
The params passed in from the javascript function can be accessed within the callback method like this: