简体   繁体   English

jQuery对话框和Repeater中的复选框问题

[英]Checkbox problems inside jQuery dialog and Repeater

So I've been basically beating my head against the wall on this for a while now. 所以我基本上已经把头撞在了墙上一段时间了。 Excuse me if I throw up too much code here, don't know a better way to explain it. 对不起,如果我在这里抛出太多代码,不知道更好的解释方法。 I've got a Repeater with an ItemTemplate of: 我有一个带有ItemTemplate的Repeater:

<ItemTemplate>
    <div id='FileFrame<%#Eval("Id")%>' class="view">
        <userControl:ConfigFiles ID=<%#Eval("Id")%> runat="server" />
    </div>
</ItemTemplate>

Some jQuery that sets up the dialog box for the div. 一些jQuery设置di​​v的对话框。

$(document).ready(function() {
        $(".view").dialog({
            autoOpen: false,
            title: "Configuration Files",
            buttons: {},
            height: 600,
            width: 800,
            open: function (type, data) { $(this).parent().appendTo("form"); }
        });
    });

and some more jQuery that opens the dialog. 以及一些打开对话框的jQuery。

$("#FileFrame"+ConfigId).dialog('open');

Now the User Control has a bunch of checkboxes inside of it inside other repeaters along with a "Download Checked Boxes" button. 现在,用户控件在其他转发器内部有一堆复选框以及“下载已检查的盒子”按钮。 The problem is that when I go through debugging and click the button, none of the checkboxes are ever read as checked unless I initially set the Checked="true" on the aspx page. 问题是,当我进行调试并单击按钮时,除非我最初在aspx页面上设置Checked =“true”,否则所有复选框都不会被读取为已检查。

Here's the a snippet from the code behind where it's failing to do what I thought it should do. 这是代码背后的代码片段,它没有做我认为应该做的事情。

foreach (RepeaterItem item in FilesRepeater.Items)
    {
        CheckBox box = item.FindControl("DownloadFileCheckBox") as CheckBox;
        if (box.Checked) //<-- always false unless I set it to true in aspx,
                         //    then it's always true
            {/*do work here*/}
    }

Any suggestions? 有什么建议么?

I had similar problem ( postback doesn't populate control values) sometime back. 有时候我有类似的问题(回发不会填充控制值)。 The problem was generated dialog was outside the form tag. 生成的问题对话框在表单标记之外。

Use 采用

$("#FileFrame"+ConfigId).parent().appendTo($("form:first"));  

or similar code to move the dialog code inside of form 或类似的代码来移动窗体内的对话框代码

Hope this will help. 希望这会有所帮助。

Ok, I'm not 100% sure what exactly happened (which is scary) but the code now works. 好吧,我不是100%确定究竟发生了什么(这是可怕的),但代码现在有效。 My intuition says that something, somewhere, was wrong with a piece of JavaScript and causing the browser to just abandon the following JS. 我的直觉说某个地方出现了一些错误,导致浏览器放弃了以下的JS。 Bottom-line is that the solution that I posted in the question does work. 最重要的是,我在问题中发布的解决方案确实有效。

I think the main problem was that there was a JS function that I was calling that wasn't being loaded or wasn't within the scope of where the call was being made. 我认为主要问题是我正在调用的JS函数没有被加载或者不在调用的范围内。 If I find out more I'll be sure to post it here. 如果我发现更多,我一定会在这里发布。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM