Find the unchecked check boxes with jQuery and pass the Names to the C # code

This is my code:

public class MyCollection {
        internal static Dictionary MyCheckBox = new Dictionary();
    }

    protected void Page_Load(object sender, EventArgs e) {

        if (!IsPostBack) {
            CheckBox chk1 = new CheckBox();
            chk1.ID = "chk1";
            chk1.Checked = true;
            if (!MyCollection.MyCheckBox.ContainsKey(chk1.ID))
                MyCollection.MyCheckBox.Add(chk1.ID, chk1);

            CheckBox chk2 = new CheckBox();
            chk2.ID = "chk2";
            chk2.Checked = true;
            if (!MyCollection.MyCheckBox.ContainsKey(chk2.ID))
                MyCollection.MyCheckBox.Add(chk2.ID, chk2);

            pl1.Controls.Add(chk1);
            pl2.Controls.Add(chk2);
        }
    }

    protected void btn1Click(object sender, EventArgs e) {
        lit1.Text = "Chk1.Checked: " + MyCollection.MyCheckBox["chk1"].Checked.ToString();
        lit1.Text += "
Chk2.Checked: " + MyCollection.MyCheckBox["chk2"].Checked.ToString(); }

i have 2 checkboxes, but always when press the button, Checkboxes.Checked are true, also when i unchecked them, how can i hold checkboxes in some dictionary like above and check their Checked property in right way? actualy i do’t want any event for change Checkboxes, I Think about a jQuery script, that when i press the button retrive me the name of checkboxes that unchecked i find a jQuery that can find the checkboxe names that unchecked but i don’t know how can pass the names to the c# code?

my above code is just a sample and real project is a user control that dynamically define and render controls from a type, hmm the scenario is like this: the clients add the assembly of user control and declare a property of that named target type, user control read target and for each property decide which control must be add so by overrided RenderContents and other methods can add controls to page, so every control automatically have a Checkbox that enable/disable control and i need the checked property

i find this code in Stackoverflow…

var sList = "";
$('input[type=checkbox]').each(function () {
var sThisVal = (this.checked ? "1" : "0");
sList += (sList=="" ? sThisVal : "," + sThisVal);
});
console.log (sList);

but this code just write sList on console how can retrive the sList values in C# Code?

Use this one maybe useful this is all of your needed test it and let me know about the result:

Loop through checkboxes and count each one checked or unchecked

Hello, buddy!稿源:Hello, buddy! (源链) | 关于 | 阅读提示

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Find the unchecked check boxes with jQuery and pass the Names to the C # code

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录