I have create one web part in sharepoint 2010. In CreateChildControls() method i write following code.
Panel pnlPropertyDiv;
Button btnEmployee;
CheckBoxList plist;
CheckBoxList rlist;
HtmlGenericControl divleft = new HtmlGenericControl("div");
HtmlGenericControl divmiddle = new HtmlGenericControl("div");
protected override void CreateChildControls()
{
plist = new CheckBoxList();
plist.ID = "ProjectCheckbox";
plist.Items.Add("p");
plist.Items[0].Attributes.Add("style", "display:none");
rlist = new CheckBoxList();
rlist.ID = "ResourceCheckbox";
rlist.Items.Add("r");
rlist.Items[0].Attributes.Add("style", "display:none");
Panel pnlContainer = new Panel();
pnlContainer.ID = "Project_Container";
this.Controls.Add(pnlContainer);
pnlPropertyDiv = new Panel();
divleft.ID = "left";
divleft.Attributes["style"] = "float:left; border-right: 1px solid #E1E3E4;height: 65px;text-align: center;width: 200px;";
pnlPropertyDiv.Controls.Add(divleft);
divleft.Controls.Add(plist);
divmiddle.ID = "middle";
divmiddle.Attributes["style"] = "float:left; border-right: 1px solid #E1E3E4;height: 65px;text-align: center;width: 200px;";
pnlPropertyDiv.Controls.Add(divmiddle);
divmiddle.Controls.Add(rlist);
HtmlGenericControl divfooter = new HtmlGenericControl("div");
divfooter.ID = "footer";
divfooter.Attributes["style"] = "text-align: center";
btnEmployee = new Button();
btnEmployee.ID = "btnEmployee";
btnEmployee.Text = "Apply";
btnEmployee.Click += new EventHandler(btnEmployee_Click);
divfooter.Controls.Add(btnEmployee);
pnlPropertyDiv.Controls.Add(divfooter);
pnlPropertyDiv.ID = "EditProperties";
pnlPropertyDiv.Attributes.Add("style", "width: 410px;position:fixed;top:45px;right:18px;z-index:1;color: #6C6E70;font-family: 'Segoe UI',Tahoma,Verdana,sans-serif;font-size: 8pt;");
this.Controls.Add(pnlPropertyDiv);
}
using jquery i add new checkbox in checkbox list.Below is my button event code.
project = "";
resource = "";
foreach (ListItem pclist in plist.Items)
{
if (pclist.Selected == true)
{
project += pclist.Text;
}
else
{
}
}
foreach (ListItem rclist in rlist.Items)
{
if (rclist.Selected == true)
{
resource += rclist.Text;
}
else
{
}
}
My problem is when i click my button i am not able to get checkbox which is added by jquery.Because CreateChildControls() method always call first and override checkboxlist control so changes apply by jquery is override.
Note:-
I am not able to use ispostback because CreateChildControls() have must call when page refresh.
I’m not convinced you will beable to access the checkbox added by jquery within the c# code behind. The jquery checkbox won’t be added to the .Net control tree so won’t be accessible to any server side processing.
You can do the other way. Add a control in C# then access through JQuery. Standard stuff.
Could you put the control in a div with style=”display:none” set then use JQuery to show it.
That might work for you?