Brief overview of my problem......I have certain text boxes(say, txtbox2) in a page that have to be filled only if certain other text boxes(say, txtbox1) are filled. For this, I have disabled the requiredfield validators for txtbox2 in the asp.net code and then wrote a javascript to enable these text boxes on the required conditions. All this works well....
In my submit button I have written this,
my javascript
this validates the page and then goes to the javascript for other validations. My problem now is, if the user fills in a txtbox1 it would enable the requiredfield validator for the other txtbox2.
But if the user decides not to fill the txtbox2 and deletes text from txtbox1, still the txtbox2's requiredfield validator remains enabled and the Page_ClientVali date throws the error that the txtbox2 has to be filled.
In my javascript I am enabling and also disabling the requriedfield validators on the specifed conditions.
But since the Page_ClientVali date does not go to the javascript, it throws this error..which is quite logical...as it is validating the page first and the txtbox2's is a requiredfield.. ..
I have been struggling for a logic which would help me disable the validators when the txtbox1 is filled and then again deleted....can somebody please guide me on this..thank you..
In my submit button I have written this,
Code:
OnClientClick="if(Page_ClientValidate()) return Check();"
Code:
Function Check() { var Valtxtbox1 = document.getElementById("<%=txtbox1.ClientID%>").value; var Valtxtbox2 = document.getElementById("<%=txtbox2.ClientID%>").value; if((Valtxtbox1 != '') && (Valtxtbox2 == '')) { alert('Please enter in txtbox2'); ValidatorEnable(document.getElementById('required_txtbox2'), true); return false; } if ((Valtxtbox2 != '') && (Valtxtbox1 == '')) { if(parseInt(Valtxtbox2)) { alert('Please enter in txtbox1'); ValidatorEnable(document.getElementById('required_txtbox1'), true); } else { document.getElementById("<%=txtbox1.ClientID%>").value = ''; } return false; } if ((Valtxtbox1 == '') && (Valtxtbox2 == '')) { ValidatorEnable(document.getElementById('required_txtbox1'), false); ValidatorEnable(document.getElementById('required_txtbox2'), false); } return true; }
But if the user decides not to fill the txtbox2 and deletes text from txtbox1, still the txtbox2's requiredfield validator remains enabled and the Page_ClientVali date throws the error that the txtbox2 has to be filled.
In my javascript I am enabling and also disabling the requriedfield validators on the specifed conditions.
But since the Page_ClientVali date does not go to the javascript, it throws this error..which is quite logical...as it is validating the page first and the txtbox2's is a requiredfield.. ..
I have been struggling for a logic which would help me disable the validators when the txtbox1 is filled and then again deleted....can somebody please guide me on this..thank you..
Comment