[RESOLVED] Html Checkbox Get Value of checked item

Hello I am creating Dynamic Control.

I want to retrive value of selected Checkbox. below i written source of checbox.

<input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_0" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$0" type="checkbox">
<input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_1" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$1" type="checkbox">
<input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_2" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$2" type="checkbox">

My Code Is below.

if (Session["CurrentControlObjType"] == "Checkbox")
                {
                    StringBuilder items = new StringBuilder();
                    string[] item = null;
                    for (int i = 7; i < Request.Form.Count - 1; i++)
                    {
                        string tmp = Request.Form[i];
                        if (!string.IsNullOrEmpty(tmp))
                        {
                            item =(tmp.Split(new char[] { ',' }));


                        }
                    }
                    strbuild.Append("<<" + Session["CurrentControlCaption"] + "$$" + Session["CurrentControlId"] + "$$" + item + ">>");


<input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_0" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$0" />Other, Please specify
<input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_1" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$1" />ddd</
input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_2" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$2" />ccde<
                }

what is solution for retrive my Value.


Hello prajapatiamit,

I cud'nt figure out the actual source code for your design.

But still.

If your checkboxes are web server controls then you can easily access the controls by their ids and check their checked property to determine whether they are checked or not.

If you have used checkboxlist then you can loop throught each items in the checkboxlist.items collection and check the Selected property of each item.

If you have used the html input controls then remember that the request.forms collection that you are using consists of only those items that are checked.

 

Hope been helpful

 

 

If you have used the html input controls then remember that the request.forms collection that you are using consists of only those items that are checked. My answer is yes I m getting only check item but strange issue is i m getting string 'on'. what is that meaning. u have any idea.

prajapatiamit2003

but strange issue is i m getting string 'on'. what is that meaning

It's meaning is that your checkbox controls have "on" values in their value property.

 

Can you please show the design code once again coz in your previous post their was some problem. I can't see it.

 

 

<input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_0" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$0" />
<input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_1" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$1" />
<input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_2" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$2" />
<input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_0" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$0" />
<input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_1" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$1" />
<input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_2" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$2" />
<input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_0" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$0" /> <input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_1" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$1" /><
Hello I am not able to paste HTML content here. if try paste HTML control it convert in design <input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_0" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$0" /> <input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_1" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$1" /><
<table id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010" border="0" style="width:500px;">
					<tr>
						<td><input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_0" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$0" /><label for="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_0">Other, Please specify</label></td>
					</tr><tr>
						<td><input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_1" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$1" /><label for="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_1">ddd</label></td>
					</tr><tr>
						<td><input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_2" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$2" /><label for="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_2">ccde</label></td>
					</tr>
				</table>


 

Hi prajapati

From your code it seems like you are using checkboxlist control. I'm preety sure of that

Here is a sample code you can check for it.

StringBuilder strbuild = new StringBuilder();
               
                strbuild.Append("<<" + Session["CurrentControlCaption"] + "$$" + Session["CurrentControlId"] + "$$");

                foreach (ListItem chkItem in chklist.Items)
                {
                    
                    if (chkItem.Selected)
                    {
                        strbuild.Append(chkItem.Text + "," ); // or chkItem.Value for values.

                    }
                }
                if (strbuild.ToString().Substring(strbuild.Length, 1) == ",")
                    strbuild.Remove(strbuild.Length, 1);

                strbuild.Append(">>");

Here i'm assuming that the name of your checkbox list is chklist

 

Hope been helpful

 

Hi prajapati

You can use this javascript code for find checkbox item value.


<script type="text/javascript" language="javascript">
    function GetValue() {
        var divCollection = document.getElementsByTagName('input');
        for (var i = 0; i < divCollection.length; i++) {
            if (divCollection[i].id.indexOf('chkSelect|') != '-1') {
                if (document.getElementById(divCollection[i].id).checked) {
                    var checkId = divCollection[i].id.split('|');
                    if (document.getElementById('<%=hdnSelect.ClientID%>').value == '') {
                        document.getElementById('<%=hdnSelect.ClientID%>').value = checkId[1];
                    }
                    else {
                        document.getElementById('<%=hdnSelect.ClientID%>').value = document.getElementById('<%=hdnSelect.ClientID%>').value + '|' + checkId[1];

                    }
                }
            }
        }

        return true;
    }
  
    
</script>


If this post  help you then Mark as Answer.


Hello I am generating this checkbox dynamically so i am not able to find this checkbox.

If you are generating your control dynamically at runtime have given their IDs then you may need to recreate them on Page_Init event, so that you can access them. I hope you have given them some Ids.

But if you haven't then you might come across some problem, as request.form is the collection of key value pair elements where key is the name of your control and value is the value field of the element.

This is all I can say, unless you show us the code you used to generate these controls.

 

Hope been helpful

 

I am creating Each Control on Button Click. each only one control like wizard type.

Hi prajapatiamit,

Creating controls dynamically at runtime comes with a cost. Asp.net is stateless. So it doesn't have any way to know it's state. Controls are on their own to save their state, either using viewstate or session or input fields.

On way to restore the state of a dynamically created control is to recreate them on postback in Page_Init event. Asp.net automatically sets their corresponding values so that you can access them later on. However your request.form consists of the collection of key value pairs where key is the name of your control and value is the corresponding value of the control. And remember as i told you before, in case of check box and radio buttons only the 1 that was selected in the browser are posted in the request.form collection. All others are discarded on postback from the browser.

So If you want to use the request.form collection then you need to know the id or name of your input element. Remember the server controls id and name when rendered are appended with the contentplaceholder's client id . If you control is inside contentplace holder with id "MainContent" then you can get the name of your dynamic control as this.

string chkid=MainContent.ClientID + "_" + "your_checkboxidorname";

then check the value in the form collection

if(Request.Form[chkid]==null) then

//this means your checkbox was not selected

else

//this means your checkbox was selected.

Same thing goes for the rest of your checkboxes.

It's difficult, isn't it?

 

You can also create the page variables for your checkboxes. Recreate them once again in your page_Init event and access them wherever you require. But this may not work for you as your controls are dynamically added depending upon current wizard step.

You can also place the controls statically in the page and set them to invisible and make them visible only when required. This way you won't have any problem accessing them wherever you want.

If you are developing wizard like interface then use the wizard control of asp.net

Check out these links for that

http://www.4guysfromrolla.com/articles/061406-1.aspx

http://weblogs.asp.net/scottgu/archive/2006/02/21/438732.aspx

 

Hope been helpful

 

hi

Thank you for your prompt reply.

I am able to get checked value of checkbox , but it return value 'ON'.

I need a Label Value.

My Same code is working fine with Radio button , and other control, just issue with checkbox  control only.


You need to make sure that the values of your checkboxes are set.

 

hi

1. <table id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010" border="0" style="width:500px;">
   2.                     <tr>
   3.                         <td><input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_0" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$0" /><label for="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_0">Other, Please specify</label></td>
   4.                     </tr><tr>
   5.                         <td><input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_1" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$1" /><label for="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_1">ddd</label></td>
   6.                     </tr><tr>
   7.                         <td><input id="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_2" type="checkbox" name="ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$2" /><label for="ctl00_ContentPlaceHolder1_Survey_Preview1_chk2107159010_2">ccde</label></td>
   8.                     </tr>
   9.                 </table>

when i click on first checkbox then i return "ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010$0" this is true, but it value id 'on'

i need a value 'Other, Please specify'.



Hi prajapatiamit,

Try this first.

Yourcheckbox.Attributes.Add("value", "yourdesiredvalue");

for each checkbox control

If this doesn't work then

Create htmlgeneric control instead of web server controls as:

CheckBox chk = new CheckBox();
            System.Web.UI.HtmlControls.HtmlInputCheckBox chk2 = new System.Web.UI.HtmlControls.HtmlInputCheckBox();
            Label lbl = new Label();
            chk2.ID = "mychkcontrol";
            chk2.Value = "1";
            lbl.Text = "Other Please specify";
            
            Page.Controls.Add(chk2);
            Page.Controls.Add(lbl);

Hope been helpful

 

HTML checkboxes only return the value "on" when the form is submitted and
they are checked, or nothing when they are not checked. 


Same issue i have i found from below link but not found my solution.

http://bytes.com/topic/asp-net/answers/324856-accessing-html-checkbox


I have already told you that if the checkbox controls have their value attribute set then it returns the value, but if it doesn't have it's value property set then it return "On".

In your case, if you look at the rendered code, then the control's values(value attribute) are not set. That's why when you try to get the value from the form collection it returns On.

Try my previous solution. Add the attribute "value" for each checkbox control and see the rendered code in your browser as before. It the input element contains the value attribute then that value will be returned to you in your form collection.

And remember only those checkboxes are posted to the server which are checked.

Please try this at least.

 

 

 

Hello I am not able to under stand what r u saying

I m generation Chekcbox using Below code

#region Checkbox
                                    // XmlNodeList dataSource = DataSource.SelectNodes("item");
                                    CheckBoxList rcbList = new CheckBoxList();
                                    rcbList.ID = obj.Id;


                                    if (obj.Mandatory == "true")
                                    {
                                        lblCaption.Text = "Q." + QuestinNO + " of " + countquestion + ".  " + obj.Caption;
                                        tcLabel.InnerHtml = "<em class='Mandatory'>* </em>";


                                    }
                                    else
                                    {
                                        lblCaption.Text = " " + "Q." + QuestinNO + " of " + countquestion + ".  " + obj.Caption;
                                    }






                                    rcbList.Width = Convert.ToInt32(obj.Width);


                                    tcLabel.Controls.Add(lblCaption);




                                    tcControl.Controls.Add(rcbList);




                                    trField.Cells.Add(tcLabel);


                                    trblankrow.Cells.Add(tcBlankcol); //For BlankRow
                                    tcBlankcol.Style.Add("height", "10px");
                                    tcLabel.Style.Add("height", "30px");


                                    tccolumn2.Style.Add("width", "100px");


                                    trControl.Cells.Add(tccolumn2); //for colspan
                                    trControl.Cells.Add(tcControl);






                                    tblAdditionalInfo.Controls.Add(trField);
                                    tblAdditionalInfo.Controls.Add(trblankrow);
                                    tblAdditionalInfo.Controls.Add(trControl);


                                    trField.Attributes.Add("class", "Section");








                                    List<String> Source = new List<string>();
                                    XmlAttribute DefaultAttribute;
                                    int DefaultIndexCnt = -1;
                                    int DefaultIndex = -1;


                                    string b = obj.Item;
                                    string[] words = b.Split('$', '$');


                                    foreach (string word in words)
                                    {


                                        if (word != "")
                                        {
                                            Source.Add(word);
                                        }
                                    }






                                    rcbList.RepeatDirection = RepeatDirection.Vertical;
                                    rcbList.DataSource = Source;
                                    rcbList.DataBind();
                                    if (DefaultIndex >= 0)
                                        rcbList.Items[DefaultIndex].Selected = true;


                                    //this.Controls.Add(tblAdditionalInfo);


                                    epp2SurveyPL.CustomFieldsDataProperties objField = new epp2SurveyPL.CustomFieldsDataProperties();
                                    objField.FieldId = obj.Id;
                                    objField.FieldType = obj.Type;
                                    objField.Caption = obj.Caption;
                                    FieldIds.Add(objField);


                                    if (words.Contains("Other, Please specify"))
                                    {
                                        TextBox txtCustom = new TextBox();
                                        txtCustom.ID = "txtother" + obj.Id;
                                        txtCustom.MaxLength = obj.MaxLength == String.Empty ? 0 : Convert.ToInt32(obj.MaxLength);
                                        txtCustom.TextMode = TextBoxMode.MultiLine;
                                        txtCustom.Rows = 5;
                                        txtCustom.Columns = 40;
                                        tcControl.Controls.Add(txtCustom);
                                        trControl.Cells.Add(tcControl);
                                        tblAdditionalInfo.Controls.Add(trControl);
                                        trField.Attributes.Add("class", "Section");
                                        objField.FieldId = "txtother" + obj.Id;
                                        objField.FieldType = "TextBox";
                                        objField.Caption = "";
                                        FieldIds.Add(objField);
                                    }


                                    this.Controls.Add(tblAdditionalInfo);


                                    Session["PersonalCustomFields"] = FieldIds;
                                    #endregion


So as I told you before you have been using checkbox list control to render those checkboxes.

You still haven't given me your design code. However I can still try.

So based on what you have said earlier

prajapatiamit2003

I am able to get checked value of checkbox , but it return value 'ON

In that case just add the following line of code

 

//instead of these lines
//rcbList.DataSource = Source;
//rcbList.DataBind();

//use these lines


            foreach(string s in source)
            {
                
                rcbList.Items.Add(new ListItem(s,s));

            }

 

 

 

Hope been helpful

I tried with your code same issue.

here i am sending my design code.

HtmlTableRow trButtonRow = new HtmlTableRow();




                trButtonRow.Attributes.Add("class", "buttonrow");


                //trButtonRow.Style["buttonrow"]
                HtmlTableCell tcButtoncell1 = new HtmlTableCell();
                tcButtoncell1.Style["text-align"] = "right";
                tcButtoncell1.ColSpan = 4;




                int rowIndex = Convert.ToInt32(ViewState["QuestionNo"]);
                int j = 0;
                int countquestion = Qlist.Count;
                foreach (epp2SurveyPL.ContractClass.SurveyQuestion obj in Qlist)
                {
                    if (j == rowIndex)
                    {
                        Label lblCaption = new Label();
                        HtmlTableRow trField = new HtmlTableRow();
                        HtmlTableCell tcLabel = new HtmlTableCell();
                        HtmlTableCell tcmandatory = null;
                        HtmlTableCell tcbgcolumn = new HtmlTableCell();
                        HtmlTableCell tccolumn = new HtmlTableCell();
                        HtmlTableCell tccolumn2 = new HtmlTableCell();
                        HtmlTableCell tccolumn1 = new HtmlTableCell();
                        HtmlTableCell tcControl = new HtmlTableCell();






                        HtmlTableRow trControl = new HtmlTableRow();
                        HtmlTableRow trblankrow = new HtmlTableRow();
                        HtmlTableCell tcBlankcol = new HtmlTableCell();


                        HtmlTableCell tcOther = new HtmlTableCell();
                        HtmlTableRow trOther = new HtmlTableRow();






                        //tcControl.ColSpan = 3;
                        tcLabel.ColSpan = 3;
                        Int32 QuestinNO = 1 + j;
                        if (countquestion == QuestinNO)
                        {
                            btnnext.Text = "Submit";
                        }




                        switch (obj.Type)
                        {
   case "Checkbox":
                                {
                                    #region Checkbox
                                    // XmlNodeList dataSource = DataSource.SelectNodes("item");
                                    CheckBoxList rcbList = new CheckBoxList();
                                    rcbList.ID = obj.Id;
                                    



                                    if (obj.Mandatory == "true")
                                    {
                                        lblCaption.Text = "Q." + QuestinNO + " of " + countquestion + ".  " + obj.Caption;
                                        tcLabel.InnerHtml = "<em class='Mandatory'>* </em>";


                                    }
                                    else
                                    {
                                        lblCaption.Text = " " + "Q." + QuestinNO + " of " + countquestion + ".  " + obj.Caption;
                                    }






                                    rcbList.Width = Convert.ToInt32(obj.Width);


                                    tcLabel.Controls.Add(lblCaption);




                                    tcControl.Controls.Add(rcbList);




                                    trField.Cells.Add(tcLabel);


                                    trblankrow.Cells.Add(tcBlankcol); //For BlankRow
                                    tcBlankcol.Style.Add("height", "10px");
                                    tcLabel.Style.Add("height", "30px");


                                    tccolumn2.Style.Add("width", "100px");


                                    trControl.Cells.Add(tccolumn2); //for colspan
                                    trControl.Cells.Add(tcControl);






                                    tblAdditionalInfo.Controls.Add(trField);
                                    tblAdditionalInfo.Controls.Add(trblankrow);
                                    tblAdditionalInfo.Controls.Add(trControl);


                                    trField.Attributes.Add("class", "Section");








                                    List<String> Source = new List<string>();
                                    XmlAttribute DefaultAttribute;
                                    int DefaultIndexCnt = -1;
                                    int DefaultIndex = -1;


                                    string b = obj.Item;


                                    string[] words = b.Split('$', '$');
                                    StringBuilder stg = new StringBuilder();
                                    foreach (string word in words)
                                    {


                                        if (word != "")
                                        {
                                            //rcbList.Items.Add(word);


                                          //  Source.Add(word);
                                            //stg.Append(word + "-");
                                            rcbList.Items.Add(new ListItem(word, word));




                                        }
                                    }




                                    Session["DropDownValue"] = stg;
                                    rcbList.RepeatDirection = RepeatDirection.Vertical;
                                    //rcbList.DataSource = Source;
                                    //rcbList.DataBind();


                                  

                                    if (DefaultIndex >= 0)
                                        rcbList.Items[DefaultIndex].Selected = true;


                                    //this.Controls.Add(tblAdditionalInfo);


                                    epp2SurveyPL.CustomFieldsDataProperties objField = new epp2SurveyPL.CustomFieldsDataProperties();
                                    objField.FieldId = obj.Id;
                                    objField.FieldType = obj.Type;
                                    objField.Caption = obj.Caption;
                                    FieldIds.Add(objField);


                                    if (words.Contains("Other, Please specify"))
                                    {
                                        TextBox txtCustom = new TextBox();
                                        txtCustom.ID = "txtother" + obj.Id;
                                        txtCustom.MaxLength = obj.MaxLength == String.Empty ? 0 : Convert.ToInt32(obj.MaxLength);
                                        txtCustom.TextMode = TextBoxMode.MultiLine;
                                        txtCustom.Rows = 5;
                                        txtCustom.Columns = 40;
                                        tcControl.Controls.Add(txtCustom);
                                        trControl.Cells.Add(tcControl);
                                        tblAdditionalInfo.Controls.Add(trControl);
                                        trField.Attributes.Add("class", "Section");
                                        objField.FieldId = "txtother" + obj.Id;
                                        objField.FieldType = "TextBox";
                                        objField.Caption = "";
                                        FieldIds.Add(objField);
                                    }


                                    this.Controls.Add(tblAdditionalInfo);


                                    Session["PersonalCustomFields"] = FieldIds;
                                    #endregion
}
   trButtonRow.Style.Add("valign", "top");
                        tblAdditionalInfo.Controls.Add(trButtonRow);

My Value Retrive code is

if (Session["CurrentControlObjType"].ToString() == "Checkbox")
{


                    string b = Request.Form[7].ToString();
                    //string n = Request["ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010_0"].ToString();
                    if (b == "on")
                    {
                        //string  n = Request.Form["ctl00$ContentPlaceHolder1$Survey_Preview1$chk2107159010_"[0]];
                    }


               

                    StringBuilder items = new StringBuilder();
                    string[] item = null;
                    for (int i = 7; i < Request.Form.Count - 1; i++)
                    {
                        int j = i - 7;
                        string tmp = Request.Form[i].ToString(); ;
                        //string[] drpvalue = Session["DropDownValue"].ToString().Split('$','$');
                        if (!string.IsNullOrEmpty(tmp))
                        {
                            
                            item = (tmp.Split(new char[] { ',' }));
                            items.Append(item[0]);

                        }
                    }
                     
                    if (Session["SavedData"] != null)
                    {
                        if (Session["SavedData"].ToString().Contains(Session["CurrentControlId"].ToString()))
                        {
                            if (Session["SavedData"].ToString().Contains(Session["CurrentControlId"].ToString()))
                            {
                                string[] CurrentQuestion = Session["SavedData"].ToString().Split(new char[] { '<', '<', '>', '>' });
                                foreach (string s in CurrentQuestion)
                                {
                                    if (s.Contains(Session["CurrentControlId"].ToString()))
                                    {
                                        Session["SavedData"] = Session["SavedData"].ToString().Replace("<<" + s + ">>", "");
                                        break;
                                    }
                                }
                            }
                            Session["SavedData"] = Session["SavedData"].ToString() + strbuild.Append("<<" + Session["CurrentControlCaption"] + "$$" + Session["CurrentControlId"] + "$$" + items + ">>");
                        }
                        else
                        {
                            Session["SavedData"] = Session["SavedData"].ToString() + strbuild.Append("<<" + Session["CurrentControlCaption"] + "$$" + Session["CurrentControlId"] + "$$" + items + ">>");
                        }
                    }
                    else
                        Session["SavedData"] = strbuild.Append("<<" + Session["CurrentControlCaption"] + "$$" + Session["CurrentControlId"] + "$$" + item + ">>");
                }

I have still issue.

Hi prajapatiamit,

First you need to recreate the controls by calling the same function or  by creating another function in Page_init event. But make sure you recreate  them.
After that in the function where you are actually trying to read the values from the checkboxes, get the checkboxlist as follows.

HTMLTable tblAdditionalInfo=this.FindControl("tblAdditionalInfo_id");//here tblAdditionalInfo_id is the id of your dynamically created tbladditionalInfo html table. or if your tblAdditionalInfo isn't added at runtime then you don't need to get it above way. You can reference it directly.

HtmlTableRow trControl=tblAdditionalInfo.Rows[trcontrol_index]// trcontrol_index is  the index of the trControl. It is hard to know the index but it's the same order you added. From the code it seems like the index must be 2.

HTMLTableCell tcControl=trControl.Cells[tcControl_index]//tcControl_index is the index of the the cell. It must be 1;

CheckBoxList rcbList=tcControl.FindControl('rcbList_id') as CheckBoxList;//I guess rcbList_id can be taken from obj.Id as per your code.

//If you are able to come so far then, Now check for rcblist . If it's null then simply try this to get your checkboxlist as follows.

CheckBoxList rcbList=this.FindControl('rcbList_id');

//Now you have your checkboxlist. Now loop through each listitem in the list.

foreach (ListItem item in lst.Items)
            {
                if (item.Selected)
                {
                    string strItem = item.Text; //or item.Value;
					//add it to your item list. or do whatever you want .

                }
            }

Try this once and let us know. Your code seems preety hefty. Instead of creating these controls dynamically at runtime, you must rethink your strategy and go for wizard control. I'm sure you'll feel easy that way.

 

 

Hi prajapatiamit2003,

The Request.Form include key value pair.

And record which control cuase the postback.

When the checkbox cause the postback, the request.form will include the checkbox id and its status.

Thus the checkbox value is the "on", it may be the  system setting.

Hello sory for late reply

if i recreate them then my Value is lost.

I guess i told you that.

Dynamically created controls do not persist their state on postback. To do so you need to recreate the controls again in pre_init event or load event, to get their value.

Please check previous posts again.

 

thoughts on "[RESOLVED] Html Checkbox Get Value of checked item"

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>