YUI 库和 asp.net autopostback 下拉列表的问题

发布于 2024-07-24 04:56:16 字数 1225 浏览 7 评论 0原文

我们在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不爱素颜 2024-07-31 04:56:16

最后我找到了答案。 实际上,YUI 将其自己的提交事件连接到自动回发下拉列表的表单。 因此,如果用户选择取消其操作,我们需要阻止这些 YUI 事件。 为此,以下是我从 YUI 示例页面获取的代码:

var onExampleSubmit = function(p_oEvent) {

            var bSubmit = 
                    window.confirm("Are you sure you want to submit?")

            if(!bSubmit) {
                YAHOO.util.Event.preventDefault(p_oEvent);
            }

        };

        YAHOO.util.Event.on(pageForm, "submit", onExampleSubmit);

希望这对在 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:

var onExampleSubmit = function(p_oEvent) {

            var bSubmit = 
                    window.confirm("Are you sure you want to submit?")

            if(!bSubmit) {
                YAHOO.util.Event.preventDefault(p_oEvent);
            }

        };

        YAHOO.util.Event.on(pageForm, "submit", onExampleSubmit);

Hope this will help anybody who is using autopostback dropdownlist with a client side confirm message in asp.net.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文