var s = checkbox.id.substr(0, checkbox.id.lastIndexOf("_") + 1) + "btnAgreeContinue"; ; >>>>>var button = document.getElementById(s); >>>>>button.disabled = !checkbox.checked;but there must be something a bit more elegant.....
>>>>mmButton thisButton = (mmButton)this.FindControlByName(this, "btnAgreeContinue"); >>>> >>>>StringBuilder sb = new StringBuilder(); >>>>sb.Append(@"<script language='javascript' type='text/javascript'>"); >>>>sb.Append(@"function SetAgreeAndContinue(checkbox) {"); >>>>sb.Append(@"var button = document.getElementById('" + thisButton.ID + "');"); >>>>sb.Append(@"button.disabled = !checkbox.checked;"); >>>>sb.Append(@"}"); >>>>sb.Append(@"</script>"); >>>> >>>>string myscript = sb.ToString(); >>>>Page.RegisterStartupScript("S", myscript); >>>>>>>
>>public Control FindControlByName<T>(T controlToSearch, string controlID) >> where T : System.Web.UI.Control >>{ >> Control matchingControl = null; >> >> try >> { >> foreach (Control subControl in controlToSearch.Controls) >> { >> if (subControl.ID != null && subControl.ID.EndsWith(controlID)) >> { >> matchingControl = subControl; >> break; >> } >> else >> { >> if (matchingControl != null) >> // found it >> break; >> else if (subControl.HasControls()) >> { >> matchingControl = this.FindControlByName(subControl, controlID); >> } >> } >> } >> } >> catch (Exception e) >> { >> throw; >> } >> return matchingControl; >>} >>>
protected override void OnInit(EventArgs e) { StringBuilder sb = new StringBuilder(); sb.Append(@"function SetAgreeAndContinue(checkbox) {"); sb.Append(@"var button = document.getElementById('ctl00_ctl00_Retirement Mangement System_cphOuterContent_cphMainContent_RightContent_ctrlAgreement_btnAgreeContinue');"); sb.Append(@"button.disabled = !checkbox.checked;"); sb.Append(@"}"); Page.ClientScript.RegisterClientScriptBlock(GetType(), "AgreementScript", sb.ToString(), true); base.OnInit(e); }At least I know that is the ClientID of the control at runtime, so I will get the clientId of the checkbox to see if it is a match minus the ending. I fear the spaces may be an issue also, so I may track down how this is calculated and make some nameing changes. Like RMS instead of that long name whereever that comes from.