Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Javascript set button enable on checkbox true
Message
From
16/10/2010 11:25:08
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 4.0
Application:
Web
Miscellaneous
Thread ID:
01485567
Message ID:
01485730
Views:
32
>
>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.
Tim
Timothy Bryan
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform