Click here to Skip to main content
15,065,914 members
Home / Discussions / C#
   

C#

 
GeneralRe: DataTable - Inserting columns Pin
Bart9-Sep-12 23:44
MemberBart9-Sep-12 23:44 
GeneralRe: DataTable - Inserting columns Pin
Eddy Vluggen10-Sep-12 0:07
professionalEddy Vluggen10-Sep-12 0:07 
GeneralRe: DataTable - Inserting columns Pin
Bart10-Sep-12 0:43
MemberBart10-Sep-12 0:43 
AnswerRe: DataTable - Inserting columns Pin
Bart10-Sep-12 0:42
MemberBart10-Sep-12 0:42 
GeneralRe: DataTable - Inserting columns Pin
Eddy Vluggen10-Sep-12 1:27
professionalEddy Vluggen10-Sep-12 1:27 
QuestionAutomatic login + getting cookie information Pin
alikalik9-Sep-12 7:32
Memberalikalik9-Sep-12 7:32 
AnswerRe: Automatic login + getting cookie information Pin
Mycroft Holmes9-Sep-12 14:40
professionalMycroft Holmes9-Sep-12 14:40 
QuestionC# Validation Pin
rmorton9-Sep-12 5:37
Memberrmorton9-Sep-12 5:37 
XML
I am trying to create a simple form that uses radio buttons.  I set the radio button to AutoPostBack = True, this way if the radio button is true/false, a subpanel is Shown or Hidden.  The radio buttons are required fields.  I also have a hidden textbox that the value of the selected radio button is inserted and this textbox is what I validate against (empty or not).

Problem 1:

This works until you go to submit and the validation fails.  The validation messages show, then when you click on one of the radio buttons with AutoPostBack = True, all the validation disappear.  I can resolve this by adding Page.Validate() to the method that runs when the radio button is clicked.  But, I do not want the Page.Validate() to run unless the page was already showing validation errors (so it will not re-validate unless the form was already submitted and failed the validation).

As it stands, before the form is submitted and fails validation: when you click on any radio button question, all the other questions requiring validation show the validation error.  I am only looking to overcome the AutoPostBack which is clearing all the validation messages that are shown when you had click submit.

Problem 2:

I would like to be able to change the color of the question if it does not pass validation.  I added the javascript to override the default .net settings.  I got this to work, but only when you click the submit button and not after a RadioButton AutoPostBack.

Currently, When you click submit all the required questions turn red and also display the required validation message.  But if you click a radio button to start fixing the validation errors, on the AutoPostBack, the all the questions that were now red in color changes back to the orignal black and the required validation message is still shown.  How can I call the Javascript to run again along with the Page.Validation() in the code behind method?

Any help would be greatly appricated! Thanks


Below is an example of the code so far.

ASPX Code:

<asp:Table ID="Table1" runat="server" CellSpacing="0" CellPadding="0">
<asp:TableRow>
<asp:TableCell CssClass="question">
<label>4. Have you had an abnormal result from a prenatal test (e.g. amniocentesis, blood test, ultrasound)?</label>

</asp:TableCell>
<asp:TableCell CssClass="answer">
<ul class="selectGroup">
<li>
<asp:RadioButton ID="Q4_true" runat="server" Checked='<%# Bind("Q4_yes") %>' Text="Yes"
GroupName="4" OnCheckedChanged='RB_QuestionSubPane_YN' AutoPostBack="true" /></li>
<li>
<asp:RadioButton ID="Q4_false" runat="server" Checked='<%# Bind("Q4_no") %>' Text="No"
GroupName="4" OnCheckedChanged='RB_QuestionSubPane_YN' AutoPostBack="true" />
</li>
<asp:TextBox ID="Q4_validationBox" runat="server" CssClass="hiddenField" Enabled="false"
Text=''></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" EnableViewState="true" ControlToValidate="Q4_validationBox"
Display="Dynamic" runat="server" ErrorMessage="RequiredFieldValidator"></asp:RequiredFieldValidator>
</ul>
</asp:TableCell>
</asp:TableRow>
</asp:Table>



Code Behind

protected void RB_QuestionSubPane_YN(object sender, EventArgs e)
{

RadioButton radio_Selected = (RadioButton)sender;
string radio_QuestionID = Convert.ToString(radio_Selected.ID);

(((TextBox)FormView1.FindControl(strQuestionID + "_validationBox")).Text) = radio_Selected.ID.ToString();

Page.Validate();

}

JavaScript

ValidatorUpdateDisplay = function (val) {
var ctl = $('#' + val.controltovalidate);
var eCount = 0;
for (var i = 0; i < Page_Validators.length; i++) {
var v = Page_Validators[i];
if (v.controltovalidate == val.controltovalidate) {

if (!v.isvalid) {
eCount++;
ctl.addClass('validationError');
$('td.question:eq(' + i + ')').addClass('red');
}

};
}
if (eCount > 0) {
ctl.addClass('validationError');

} else {
ctl.removeClass('validationError');
$('td.question:eq(' + i + ')').removeClass('red');
}
if (typeof (val.display) == "string") {
if (val.display == "None") {
return;
}
if (val.display == "Dynamic") {
val.style.display = val.isvalid ? "none" : "inline";
return;
}
}
if ((navigator.userAgent.indexOf("Mac") > -1) &&
(navigator.userAgent.indexOf("MSIE") > -1)) {
val.style.display = "inline";
}
val.style.visibility = val.isvalid ? "hidden" : "visible";
}

QuestionProgram Working Very Slow Pin
mohammadkaab9-Sep-12 4:54
Membermohammadkaab9-Sep-12 4:54 
AnswerRe: Program Working Very Slow Pin
Eddy Vluggen9-Sep-12 5:41
professionalEddy Vluggen9-Sep-12 5:41 
GeneralRe: Program Working Very Slow Pin
mohammadkaab9-Sep-12 6:33
Membermohammadkaab9-Sep-12 6:33 
Questionremove items from Listbox Pin
scottichrosaviakosmos9-Sep-12 4:38
Memberscottichrosaviakosmos9-Sep-12 4:38 
AnswerRe: remove items from Listbox Pin
Eddy Vluggen9-Sep-12 5:39
professionalEddy Vluggen9-Sep-12 5:39 
GeneralRe: remove items from Listbox Pin
scottichrosaviakosmos9-Sep-12 5:55
Memberscottichrosaviakosmos9-Sep-12 5:55 
GeneralRe: remove items from Listbox Pin
Eddy Vluggen9-Sep-12 5:57
professionalEddy Vluggen9-Sep-12 5:57 
GeneralRe: remove items from Listbox Pin
scottichrosaviakosmos9-Sep-12 9:07
Memberscottichrosaviakosmos9-Sep-12 9:07 
GeneralRe: remove items from Listbox Pin
Eddy Vluggen9-Sep-12 21:32
professionalEddy Vluggen9-Sep-12 21:32 
GeneralRe: remove items from Listbox Pin
scottichrosaviakosmos12-Sep-12 20:55
Memberscottichrosaviakosmos12-Sep-12 20:55 
GeneralRe: remove items from Listbox Pin
Eddy Vluggen12-Sep-12 21:17
professionalEddy Vluggen12-Sep-12 21:17 
Questionhow to find all elements of a webpage Pin
hosseinDolat9-Sep-12 1:09
MemberhosseinDolat9-Sep-12 1:09 
AnswerRe: how to find all elements of a webpage Pin
jschell9-Sep-12 4:04
Memberjschell9-Sep-12 4:04 
GeneralRe: how to find all elements of a webpage Pin
hosseinDolat9-Sep-12 15:53
MemberhosseinDolat9-Sep-12 15:53 
GeneralRe: how to find all elements of a webpage Pin
jschell10-Sep-12 8:48
Memberjschell10-Sep-12 8:48 
GeneralRe: how to find all elements of a webpage Pin
hosseinDolat10-Sep-12 14:36
MemberhosseinDolat10-Sep-12 14:36 
GeneralRe: how to find all elements of a webpage Pin
jschell11-Sep-12 8:28
Memberjschell11-Sep-12 8:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.