Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Building ClientScript in ASP.NET code behind
Message
Information générale
Forum:
Javascript
Catégorie:
Autre
Divers
Thread ID:
01610776
Message ID:
01610837
Vues:
26
Thank you for the suggestion. I agree, your approach looks easier to read.

>You should probably use string.Format() to this sort of thing:
>
>
>string clientId = "someId";
>
>string script = @"
><script>
>function DisableButton() {
>   document.getElementById('{0}').disabled = true;
>}
></script>
>";
>
>script = string.Format(script,clientId);
>
>
>Much easier to write, read and work with. Note that @"" strings have to escape double quotes (") with two double quotes ("").
>
>+++ Rick ---
>
>>Hi,
>>
>>I am trying to build in the code behind of an ASP.NET page the following Javascript function:
>>
>>
>><script type = "text/javascript">
>>            function DisableButton() {
>>
>>                document.getElementById("< %Submit.ClientID %>").disabled = true;
>>
>>              }
>>
>>              window.onbeforeunload = DisableButton;
>></script>
>>
>>
>>I want to "translate" this code into the Client Script built in code behind. But I get error on the
>>
>>
>>                    String csname2 = "ButtonClickScript";
>>                    Type cstype = this.GetType();
>>
>>                    // Get a ClientScriptManager reference from the Page class.
>>                    ClientScriptManager cs = Page.ClientScript;
>>
>>                    StringBuilder cstext2 = new StringBuilder();
>>
>>                    cstext2.Append("<script type=\"text/javascript\"> function DisableButton() {");
>>                    cstext2.Append("document.getElementById("< %=Submit.ClientID %>").disabled = true};";
>>                    cstext2.Append("window.onbeforeunload = DisableButton;");
>>                    cstext2.Append("</script>");
>>
>>
>>But I get syntax error on the line
>>document.GetElementByID... that "missing semicolon".
>>Could you see how to write this line? Please keep in mind that the actual code has Percent sign (%) instead of work Percent.
>>
>>UPDATE:
>>Solution:
>>
>>cstext2.Append("document.getElementById('" + Submit.ClientID + "').disabled = true; }");
>>
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform