Link to home
Start Free TrialLog in
Avatar of fwsteal
fwsteal

asked on

stringbuilder with javascript asp.net 2.0

How do I get the <%= blocks to render properly?

protected void Page_Load(object sender, EventArgs e)
 {
  StringBuilder javaScriptString = new StringBuilder();
   javaScriptString.Append("<script type='text/javascript'>");
   javaScriptString.Append("function validateCheckbox() {");
   javaScriptString.Append("if(!document.form1.<%= CheckBoxCA.ClientID %>.checked){");
   javaScriptString.Append("alert('The CA is required.');");
   javaScriptString.Append("return false;");
   javaScriptString.Append("}");
   javaScriptString.Append("if(!document.form1.<%= CheckBoxESA.ClientID %>.checked){");
   javaScriptString.Append("alert('The ESA is required.');");
   javaScriptString.Append("return false;");
   javaScriptString.Append("}");
   javaScriptString.Append("return true;");
   javaScriptString.Append("}");
   javaScriptString.Append("</script>");
 Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Alert", javaScriptString);
 form1.Attributes.Add("OnClientClick", "return validateCheckbox();");
}


Error: <%= CheckBoxCA.ClientID %> and <%= CheckBoxESA.ClientID %> are being rendered such and not like
the following:
<script type="text/javascript">
function validateCheckbox() {
 if(!document.form1.CheckBoxCA.checked){
    alert("The CA is required.");
   return false;
   }
 if(!document.form1.CheckBoxES.checked){
    alert("The ESA is required.");
   return false;
  }
   return true;  
 }
</script>

When the two checkboxes are redendered as <%= CheckBoxCA.ClientID %> and <%= CheckBoxESA.ClientID %> I
get an error.
ASKER CERTIFIED SOLUTION
Avatar of rundkaas
rundkaas

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial