In .net server side i was creating Dynamic controls text-box,checkbox. If i click the checkbox inside all the checkbox list controls it should get checked. refer this image.
server side using new EventHandler i can achieve this.But i want this in clientside.
Clientside code :
function CheckboxHeaderClick1() {
var chkBox = "<%=strchx1ID %>";
if (chkBox.checked) {
var checkboxList = "<%=strchxboxlist1ID %>";
var chkBoxCount = "<%=strchxboxlist1Count %>";
for (var i = 0; i < chkBoxCount.length; i++) {
chkBoxCount[i].checked = true;
}
}
else {
var checkboxList = "<%=strchxboxlist1ID %>";
var chkBoxCount = "<%=strchxboxlist1Count %>";
for (var i = 0; i < chkBoxCount.length; i++) {
chkBoxCount[i].checked = false;
}
}
}
but chkBox.checked is coming undefined.From server side to client side how i can pass the checkbox control?
My code :
System.Web.UI.WebControls.Label lbllookup = new System.Web.UI.WebControls.Label();
Panel pnl1 = new Panel();
chx1 = new CheckBox();
chx1.ID = "chx" + fieldname;
strchx1ID = chx1.ClientID;
// chx1.AutoPostBack = true;
if (!IsPostBack)
chx1.Checked = true;
// chx1.CheckedChanged += new EventHandler(this.chx1_CheckedChanged);
// chx1.Attributes.Add("onclick", "CheckboxHeaderClick1();");
chx1.Attributes.Add("onclick", "javascript:CheckboxHeaderClick1();return false;");
checkboxID = chx1.ID;
chx1.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#f2f2f2");
chx1.Style.Add(HtmlTextWriterStyle.Color, "#287082");
chx1.Style.Add(HtmlTextWriterStyle.PaddingBottom, "6px");
chx1.Style.Add(HtmlTextWriterStyle.FontSize, "14px!important;");
pnl_filters.Controls.Add(chx1);
lookupfieldcount++;
chxboxlist1 = new CheckBoxList();
chxboxlist1.ID = fieldname;
strchxboxlist1ID = chxboxlist1.ClientID;
//chx1.CheckedChanged += new EventHandler(this.chx1_CheckedChanged); lbllookup.Text = field.Title;
lbllookup.Style.Add(HtmlTextWriterStyle.BackgroundColor, "#f2f2f2");
lbllookup.Style.Add(HtmlTextWriterStyle.Color, "#287082");
//lbllookup.Style.Add(HtmlTextWriterStyle.PaddingLeft, "8px");
//lbllookup.Style.Add(HtmlTextWriterStyle.PaddingTop, "4px");
lbllookup.Style.Add(HtmlTextWriterStyle.PaddingBottom, "6px");
// lbllookup.Style.Add(HtmlTextWriterStyle.PaddingRight, "142px");
lbllookup.Style.Add(HtmlTextWriterStyle.FontSize, "14px!important;");
lbllookup.Style.Add(HtmlTextWriterStyle.Width, "240px");
pnl_filters.Controls.Add(lbllookup);
pnl1.ID = "pnl" + fieldname;
if (chxboxlist1.Height == 105)
{
pnl1.Style.Add(HtmlTextWriterStyle.Height, "105px");
pnl1.Style.Add(HtmlTextWriterStyle.OverflowY, "scroll");
}
else
{
pnl1.Style.Add(HtmlTextWriterStyle.Height, "90px");
}
pnl_filters.Controls.Add(pnl1);
pnl1.Controls.Add(chxboxlist1);
if (!IsPostBack)
bind_Fields(fieldname, listtitle, lookupfield, chxboxlist1);
if (chxboxlist1.Items.Count == 0)
bind_Fields(fieldname, listtitle, lookupfield, chxboxlist1);
checkboxcount++;
Aucun commentaire:
Enregistrer un commentaire