Reputation: 941
I am trying to convert the following JavaScript into the code behind (C#) of an ASP.NET page. This is the JavaScript:
function DisableButton() {
document.getElementById("<%=Submit.ClientID %>").disabled = true;
}
window.onbeforeunload = DisableButton;
I am trying to build a Client Script as follows (but get error message, see after the code):
StringBuilder cstext = new StringBuilder();
cstext.Append("<script type=\"text/javascript\"> function DisableButton() {");
// I get error on the following line that semi-colon is missing
cstext.Append("document.getElementById("<%=Submit.ClientID %>").disabled = true; }";
cstext.Append("window.onbeforeunload = DisableButton;");
cstext.Append("</script>");
I get error that the semi-colon is missing. What do I need to change in my code?
Upvotes: 0
Views: 786
Reputation: 656
The line
cstext.Append("document.getElementById("<%=Submit.ClientID %>").disabled = true; }";
should be
cstext.Append("document.getElementById('" + Submit.ClientID + "').disabled = true; }");
Upvotes: 1