Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Javascript set button enable on checkbox true
Message
De
15/10/2010 12:36:34
 
 
À
15/10/2010 12:26:06
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:
01485612
Vues:
30
>>>>>I couldn't get this to work. I do see the script is injected when I look in firebug but I also see when I drill down the button ID is a long name starting with ctl00_ctl00_Retirement Management System_cphOuterContent_cphMainContent_RightContent_ctrlAgreement_btnAgreeContinue
>>>>>
>>>>>Can that have anything to do with it?
>>>>
>>>>Well the string in getElementById() in the script obviously has to match to actual Id of the button in question. Can't you just give the button a specific (short) Id ?
>>>
>>>Yep, my button ID is as above, but it doesn't show up that way in firebug. The button is in a Web User Control which is added to a content page that is in a nested master. I would guess it gets altered when it is dynamically added. I do have a routine for getting the id of a control, maybe I need to obtain that in code and alter the code to pass that in.
>>
>>Sorry, I'd forgotten about that behaviour. I guess, if the checkbox and button are at the same level then this would work in the function:
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.....
>
>
>This didn't work either.

Worked for me with a usercontrol in a form but it does depend on both elements being at the same level. Given that, I don't know why it didn't work for you. But it is ugly anyway.....

> I tried my other code to FindControl and pass that in such as this so I could see what the button id was and surprising it is 'btnContinue".

So, given that the compiler didn't dream that up from scratch where did the name stem from ?

> So very frustrating to get such a simple thing to work. These things make me want to stick to WPF or Silverlight and avoid ASP.net.

Very true. Would just have been a simple binding in WPF/Silverlight....

>
>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);
>
So what does FindControlByName() look like ?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform