YUI 库和 asp.net autopostback 下拉列表的问题
我们在 asp.net 项目中使用 YUI 库。 我有一个 asp.net autopostback 下拉列表,它被转换为 YUI dropdownlist,如下所示的代码。 现在,当用户从下拉列表中选择某个值时,页面会回发并触发 SelectedGroupChanged 事件,但在此之前不会出现确认对话框。 我在这里可能做错了什么?
代码:
<asp:Button id="Groups" Enabled="false" runat="server" />
<asp:DropDownList ID="groupsDropDownList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="SelectedGroupChanged" />
<script language="javascript" type="text/javascript">
var YUIGroupsDrpDown;
<%if (Groups.Visible)
{ %>
YUIGroupsDrpDown = new YAHOO.widget.Button("<%=Groups.ClientID %>",{type:"menu", menu: "<%=groupsDropDownList.ClientID %>"});
YUIGroupsDrpDown.set("label", "<%=groupsDropDownList.SelectedItem.Text%>" );
YUIGroupsDrpDown.getMenu().subscribe("click",onGroupsChange);
YUIGroupsDrpDown.on("click", {fn: TakeActions, obj: 'M'});
<%} %>
function onGroupsChange()
{
YUIGroupsDrpDown.set("label", YUIGroupsDrpDown.getMenu().activeItem.srcElement.text );
}
function TakeActions(event, action)
{
var message = 'some message'
if (window.confirm(strMsg) != 1)
return false;
else
return true;
}
We are using YUI library in our asp.net project. I have a asp.net autopostback dropdown list which is converted to YUI dropdownlist as the code shown below. Now when user select some value from the dropdownlist the page posts back and the SelectedGroupChanged event fires but before that the confirm dialog box is not appearing. What I could be doing wrong here?
Code:
<asp:Button id="Groups" Enabled="false" runat="server" />
<asp:DropDownList ID="groupsDropDownList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="SelectedGroupChanged" />
<script language="javascript" type="text/javascript">
var YUIGroupsDrpDown;
<%if (Groups.Visible)
{ %>
YUIGroupsDrpDown = new YAHOO.widget.Button("<%=Groups.ClientID %>",{type:"menu", menu: "<%=groupsDropDownList.ClientID %>"});
YUIGroupsDrpDown.set("label", "<%=groupsDropDownList.SelectedItem.Text%>" );
YUIGroupsDrpDown.getMenu().subscribe("click",onGroupsChange);
YUIGroupsDrpDown.on("click", {fn: TakeActions, obj: 'M'});
<%} %>
function onGroupsChange()
{
YUIGroupsDrpDown.set("label", YUIGroupsDrpDown.getMenu().activeItem.srcElement.text );
}
function TakeActions(event, action)
{
var message = 'some message'
if (window.confirm(strMsg) != 1)
return false;
else
return true;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后我找到了答案。 实际上,YUI 将其自己的提交事件连接到自动回发下拉列表的表单。 因此,如果用户选择取消其操作,我们需要阻止这些 YUI 事件。 为此,以下是我从 YUI 示例页面获取的代码:
希望这对在 ASP.NET 中使用带有客户端确认消息的自动回发下拉列表的任何人有所帮助。
Finally I found the answer. Actually YUI is wiring its own submit event to the form for the autopostback dropdownlist. So we need to prevent these YUI event if user chooses to cancel his action. So to do this, here's the code that I got from the YUI's example page:
Hope this will help anybody who is using autopostback dropdownlist with a client side confirm message in asp.net.