Here is my code I call the same function many times on the button click for each textbox I want to format based on validation.
Code:
function Validate(elementid, validator) { Page_ClientValidate('EditLocationValidation'); if (typeof (Page_Validators) == "undefined") return; document.getElementById(elementid).className = document.getElementById(validator).isvalid ? "RequiredFieldValid" : "RequiredFieldInValid"; }
Code:
<asp:ImageButton ID="imgbtnSave" runat="server" ImageUrl="~/images/buttons/save.png" CausesValidation="True" OnClick="imgbtnSave_Click" TabIndex="12" ValidationGroup="EditLocationValidation" OnClientClick="Validate('maincontent_LocationsView_lblLocationCode', 'maincontent_LocationsView_valLocationCode'); Validate('maincontent_LocationsView_lblLocationName','maincontent_LocationsView_valLocationName'); Validate('maincontent_LocationsView_lblAddress1','maincontent_LocationsView_valAddress1'); Validate('maincontent_LocationsView_lblURL','maincontent_LocationsView_valURL'); Validate('maincontent_LocationsView_lblCity','maincontent_LocationsView_CityRequiredFieldValidator'); Validate('maincontent_LocationsView_lblCounty','maincontent_LocationsView_CountyRequiredFieldValidator'); Validate('maincontent_LocationsView_lblCountry','maincontent_LocationsView_CountryRequiredFieldValidator');" />
So the function being re-used expects a string of the client id to look up, however apart from manual coding I cannot seem to pass it the client id from my HTML /server code