Note that there are some explanatory texts on larger screens.

plurals
  1. PORequiredFieldsValidator is not working in datalist
    primarykey
    data
    text
    <p>I got a problem when using required field validator in datalist ,</p> <p>We have 4 polls. In that user must answer two polls which are required.</p> <p>I have added all the four polls in my datalist ,it is displaying fine and while clicking submit button the required field validator is working and giving the error message. Once we answered the required polls and clicking submit button again, all other polls which are not required showing as required one.</p> <p>My poll answer getting submitted thats not a problem ,I want to avoid displaying the error message for non-required polls.</p> <p>Can you please help me to solve this problem </p> <p>Here is my design and code:</p> <p><code></p> <pre><code> &lt;div id="pollQuestion_div" Class="read-messages-poll" runat="server" &gt; &lt;asp:DataList ID="PollDataList" runat="server" onitemdatabound="PollDataList_ItemDataBound"&gt; &lt;ItemTemplate&gt; &lt;asp:HiddenField ID="PollIDReqHiddenField" Value='&lt;%# Eval("PollID") %&gt;' runat="server" Visible="false" /&gt; &lt;asp:Label ID="lblReqQuestionNumber" runat="server" Text='&lt;%# Eval("No of PollQuestion") %&gt;' Font-Bold="true"&gt;&lt;/asp:Label&gt;&lt;br /&gt; &lt;asp:Label ID="lblRequiredPollQusetion" runat="server" Text='&lt;%# Eval("PollQuestions") %&gt;' Font-Bold="true"&gt;&lt;/asp:Label&gt; &lt;asp:RequiredFieldValidator ID="RequiredFieldValidatorReqPoll" runat="server" ControlToValidate="rdblstRequiredPollOptions" Display="Dynamic" ErrorMessage="*" ForeColor="Red" &gt;&lt;/asp:RequiredFieldValidator&gt; &lt;asp:HiddenField ID="HiddenFieldPollOption" runat="server" Value='&lt;%# Eval("PollOptions") %&gt;' Visible="false" /&gt; &lt;asp:HiddenField ID="HiddenFieldPollType" runat="server" Value='&lt;%# Eval("PollType") %&gt;' Visible="false"/&gt; &lt;asp:RadioButtonList ID="rdblstRequiredPollOptions" runat="server" &gt; &lt;/asp:RadioButtonList&gt; &lt;asp:RadioButtonList ID="rdblstNonRequiredPollOptions" runat="server" &gt; &lt;/asp:RadioButtonList&gt; &lt;asp:CheckBoxList ID="CheckBoxListMultiple" runat="server" RepeatDirection="Vertical"&gt;&lt;/asp:CheckBoxList&gt; &lt;/ItemTemplate&gt; &lt;FooterTemplate&gt; &lt;asp:Button ID="btnSubmitPoll" runat="server" Text="Submit" CssClass="custom-button" OnClick="btnSubmitPoll_click" /&gt; &lt;/FooterTemplate&gt; &lt;/asp:DataList&gt; &lt;/div&gt; </code></pre> <p><strong>Datalist Item bound Code:</strong> </p> <pre> protected void PollDataList_ItemDataBound(object sender, DataListItemEventArgs e) { //Debugger.Break(); try { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { System.Data.DataRowView drv = (System.Data.DataRowView) e.Item.DataItem); string strPollID = drv.Row["PollID"].ToString(); string pollOptions = drv.Row["PollOptions"].ToString(); string strPollType = drv.Row["PollType"].ToString(); string strPollRequiredorNot = drv.Row["RequiredPoll"].ToString(); if (strPollType == "RadioButtonList") { if (strPollRequiredorNot == "Required") { RadioButtonList rbl = (RadioButtonList)e.Item.FindControl("rdblstRequiredPollOptions"); foreach (string opt in pollOptions.Split('}')) { rbl.Items.Add(opt.ToString()); } //RequiredFieldValidator rfv = new RequiredFieldValidator(); //rfv.ID = "reqfield"; //rfv.ControlToValidate = rbl.ID; //rfv.ErrorMessage = "*"; RequiredFieldValidator rfvRadioButtonList = (RequiredFieldValidator)e.Item.FindControl("RequiredFieldValidatorReqPoll"); rfvRadioButtonList.ControlToValidate = rbl.ID; } else { RadioButtonList rbl = (RadioButtonList)e.Item.FindControl("rdblstNonRequiredPollOptions"); foreach (string opt in pollOptions.Split('}')) { rbl.Items.Add(opt.ToString()); } } } else if (strPollType == "CheckBoxList") { CheckBoxList chkList = (CheckBoxList)e.Item.FindControl("CheckBoxListMultiple"); foreach (string opt in pollOptions.Split('}')) { chkList.Items.Add(opt.ToString()); chkList.RepeatDirection = RepeatDirection.Vertical; } if (strPollRequiredorNot == "Required") { //CustomValidators.RequiredFieldValidatorForCheckBoxLists rfvCheckBoxList = (CustomValidators.RequiredFieldValidatorForCheckBoxLists)e.Item.FindControl("RequiredFieldValidatorForCheckBoxLists1"); //rfvCheckBoxList.ControlToValidate = chkList.ID; } } } } catch (Exception ex) { } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload