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:
01610835
Vues:
37
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; }");
>
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform