Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Javascript set button enable on checkbox true
Message
De
16/10/2010 11:39:47
 
 
À
16/10/2010 11:25:08
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 4.0
Application:
Web
Divers
Thread ID:
01485567
Message ID:
01485732
Vues:
31
>>
>>Thanks for the code.
>>But there's no guarantee that the original Id is not duplicated elswhere on the page. So it wouldn't, for example, differentiate between
>>'ControlA_Control_B_btnAgreeContinue' and 'ControlA_ControlC_btnAgreeContinue' so you couldn't use the same user control twice on the same form.
>>My version would avoid that problem - or it would if it worked :-{
>>Did you debug to see where it was going wrong for you ?
>
>
>OK, this didn't work before but it does now. I don't know what I did different, but this is from your example. I did move it into the OnInit though.
>
>protected override void OnInit(EventArgs e)
>{
>    // Client Id of Checkbox
>    // ctl00_ctl00_Retirement Mangement System_cphOuterContent_cphMainContent_RightContent_ctrlAgreement_chkAgree
>    // Client Id of Button
>    // ctl00_ctl00_Retirement Mangement System_cphOuterContent_cphMainContent_RightContent_ctrlAgreement_btnAgreeContinue
>
>    StringBuilder sb = new StringBuilder();
>    sb.Append(@"function SetAgreeAndContinue(checkbox) {");
>    sb.Append(@"var s = checkbox.id.substr(0, checkbox.id.lastIndexOf('_') + 1) + 'btnAgreeContinue';");
>    sb.Append(@"var button = document.getElementById(s);");			
>    sb.Append(@"button.disabled = !checkbox.checked;");
>    sb.Append(@"}");
>
>    Page.ClientScript.RegisterClientScriptBlock(GetType(), "AgreementScript", sb.ToString(), true);
>    base.OnInit(e);
>}
>
>
>Thanks for all your help.

Glad you got it working. May not be worth bothering but this might be more efficient in that the look-up will only need to be done once - not every time the checkbox is clicked...:
sb.Append(@"button = null;");
sb.Append(@"function SetAgreeAndContinue(checkbox) {");
sb.Append(@"if (button == null){");
sb.Append(@"button = document.getElementById(checkbox.id.substr(0, checkbox.id.lastIndexOf('_') + 1) + 'btnAgreeContinue');");
sb.Append(@"}");
sb.Append(@"button.disabled = !checkbox.checked;");
sb.Append(@"}");
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform