javascript - Creating Controls Dynamically with JQuery .Clone() Method and then Accessing them on Button Click in asp.net -
i trying create controls of asp.net dynamically. have placed few checkboxes controls textbox, label, checkbox , when these checkboxes checked, div opened in user can set properties of these controls , add multiple controls of type on button click( jquery .clone() method ). , @ last when user clicks on "create form" button new webform opens , controls displayed on specified properties.
i having trouble accessing these dynamically created controls.
mycontrol = findcontrol("txttextboxtext_0"+i);
in line, getting first control id "txtttextboxtext_00" not getting other controls ids "txtttextboxtext_01,txtttextboxtext_02,txtttextboxtext_03,...."
i not getting doing wrong , problem. please guide.
here code of jquery.
//duplicate divs var current_id = 0; var id = 0; $("#btn_atxt").click(function () { $('#textboxdiv').css({ height: '+=77' }, 500); id = current_id + 1; document.getelementbyid("hiddentxtcount").value = id+1; current_id = id; if (id < 10) id = "0" + id; var klon = $("#txtdiv_00").clone(true); klon.attr("id", "#txtdiv_" + id); klon.attr("name", "#txtdiv_" + id); klon.find("*[id]").each(function () { $(this).attr("id", $(this).attr("id").split("_")[0] + "_" + id); $(this).appendto("#txtdiv_" + id); }); klon.find("*[name]").each(function () { $(this).attr("name", $(this).attr("name").split("_")[0] + "_" + id); $(this).appendto("#txtdiv_" + id); }); klon.appendto("#d_txt").insertbefore("#btn_atxt"); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script>
and c#,
if (chk_txt.checked == true) { control mycontrol = new control(); staticcontrols.createtextboxes(txtcount); //for dynamically created textboxes.. //"txttextboxtext_00" textbox in first div //similarly "txttextboxtext_01" textbox of dynamically created 2nd div ".clone()" method (int = 0; < txtcount; i++) { mycontrol = findcontrol("txttextboxtext_0"+i); textbox temp1 = (textbox)mycontrol; if (mycontrol != null) { textbox temp2 = new textbox(); temp2.enabled = convert.toboolean(droptxtenable_00.selecteditem.text); temp2.readonly = convert.toboolean(droptxtread_00.selecteditem.text); temp2.text = temp1.text; staticcontrols.textboxes[i] = temp2; } } }
please let me know if need else. prototype. let me know if using wrong approach , should best approach doing this?? thankx in advance.!
Comments
Post a Comment