ASP.NET表单字段未从颜色框中粘贴

本文关键字:颜色 NET 表单 字段 ASP | 更新日期: 2023-09-27 17:59:41

我有一个显示在jQuery颜色框中的表单。提交表单时,该表单中的字段不会返回到页面。我修改了javascript,将表单字段存储到提交和DO返回时的隐藏字段中。问题是,由于这是一个登录框,我真的不想那样移动密码。主要表单内容位于更新面板内。这是我主页的代码:

<form id="myform" runat="server" clientidmode="Static" method="post">
    <asp:ScriptManager ID="ecommerceManager" runat="server" ClientIDMode="Static" EnableViewState="False" EnablePageMethods="True">
        <Scripts>
            <asp:ScriptReference Path="~/js/jquery-1.6.1.min.js" />
            <asp:ScriptReference Path="~/js/jquery.colorbox.min.js" />
            <asp:ScriptReference Path="~/js/eCommerce.js" />
        </Scripts>
    </asp:ScriptManager>
    <div style="width: 940px; margin-left: auto; margin-right: auto;">
        <div align="left">
            TOP OF THE PAGE
            <asp:ContentPlaceHolder ID="bodyContent" runat="server" ClientIDMode="Static">
            </asp:ContentPlaceHolder>
            BOTTOM OF THE PAGE
        </div>
    </div>
    <script type="text/javascript">
        Sys.WebForms.PageRequestManager.getInstance().add_endRequest(closeLoading);
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(loadData);
    </script>
    </form>

以下是我的主默认页面中使用主页面的一些代码:

<asp:Content ID="mainContent" ContentPlaceHolderID="bodyContent" runat="server">

    <asp:UpdatePanel ID="ecommerceUpdate" runat="server" ClientIDMode="Static">
        <ContentTemplate>
            <asp:Panel ID="pnlEcomMain" runat="server" CssClass="ecom_main" ClientIDMode="Static">
                <asp:HiddenField ID="statusField" runat="server" ClientIDMode="Static" ViewStateMode="Disabled" EnableViewState="False" />
                <asp:HiddenField ID="hdnUsername" runat="server" ClientIDMode="Static" ViewStateMode="Disabled" EnableViewState="False" />

                <div class="add_product">
                    <div class="add_product_menu text_12_bold">
                        <asp:Image ID="imgAddProducts" ImageUrl="~/images/ecom_icon_add_2.gif" CssClass="std_btn" AlternateText="Add Products" runat="server" ClientIDMode="Static" />Add Additional Products:<br /><br />
                        <asp:DropDownList ID="newproduct" runat="server" ClientIDMode="Static" 
                            onchange="addProduct()">
                        </asp:DropDownList>
                    </div>
                </div>
                </asp:Panel>
                <div class="clear"></div>
                <!--- HERE IS THE COLORBOX POPUP CONTENT --->
            <div style="display: none; visibility: hidden;">
                <div id="inline_login">
                    <p><strong>User Login Details Go Here</strong></p>
                    User Name: <asp:TextBox ID="loginName" runat="server" ClientIDMode="Static" EnableViewState="False" ViewStateMode="Disabled" /><br />
                    Password: <asp:TextBox ID="loginPassword" runat="server" TextMode="Password" ClientIDMode="Static" /><br />
                    <input type="button" name="loginBtn" id="loginbtn" value="Login" onclick="javascript:validateLogin()" />

                </div>
            </div>
            </asp:Panel>
            <asp:Label ID="xmlContent" runat="server" />
       </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>

新产品字段正确发布,但用户名和密码不会,除非我在发布前将其复制到隐藏字段。我猜这可能是与更新面板的冲突?我最初试图让登录控制在更新面板中工作,但在论坛上读到这是一个已知的问题。

对此有任何见解,我们将不胜感激。我正在使用firebug,可以确认这些字段根本不在帖子中,这就是ASP找不到它们的原因。

ASP.NET表单字段未从颜色框中粘贴

显然,尽管颜色框在表单中,但它实际上会将内容移动到表单之外。我通过在JavaScript提交函数中添加以下代码来解决这个问题:

jQuery('#inline_login').appendTo('form'); 

希望它能帮助其他人!

我从未使用过jQuery颜色框,但我在jQuery UI模式弹出中遇到了类似的问题。它所做的是,当我附加弹出窗口时,它将内容div移到了asp.net表单之外,这样控件就不会被发布回来。

另一个在特定情况下对我有效的选项。NET CMS(DNN)将接受Jack的修复并附加到cbox_complete事件。张贴,以防其他人觉得这很有用。

$(document).bind('cbox_complete', function () {
    $("#colorbox, #cboxOverlay").appendTo('form:first');
});

刚刚在colorbox&形式,通过这种方式解决。我的问题是提交不起作用,因为字段集被去掉了表单标记;因此,如果您的表单没有在colorbox中发布,请尝试此操作,将表单id作为colorbox内容的href发送

$(document).ready(function () {
        $('#login-trigger').click(function () {
            $.colorbox({
                inline: true,
                href: "#login-form",
                close: "×",
                onOpen: function () { $('#login-content').css({ display: 'block' }); },
                onClosed: function () { $('#login-content').css({ display: 'none' }); }
            });
            return false;
        });