Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do <%=%> tags render as &quot;&lt;%=%>&quot;?

Tags:

asp.net

I have an input control on a page like this:

<input 
    type="button" 
    causesvalidation="false"
    runat="server" 
    id="resetButton"  
    value="Iptal" 
    onclick='return  
    resetForm("<%=projectValidationSummary.ClientID%>");' />

when it is rendered

<input 
    name="ctl00$ContentPlaceHolder1$EditForm$resetButton" 
    type="button" 
    id="ctl00_ContentPlaceHolder1_EditForm_resetButton" 
    value="Iptal" 
    onclick="return  resetForm(&quot;&lt;%=projectValidationSummary.ClientID%>&quot;);" />

I use <%=%> tags on page but it is rendered as

&quot;&lt;%=%>&quot;

Can anyone tell my why this is happening?

like image 917
dankyy1 Avatar asked Jul 10 '09 12:07

dankyy1


1 Answers

<%= %> is only usable inside literal html and can't be used on a server controls attribute.

Instead you should us databinding <%# %>, and in your case i think you are trying to trigger a javascript function on your client side and then your code should look like this:

<asp:button
causesvalidation="false"
runat="server"
id="resetButton"
text="Iptal"
onclientclick='<%# String.Format("return resetForm(\"{0}\");", projectValidationSummary.ClientID) %>' />

and on the server side you should bind the attribute with this code (probably in the Page.Load event):

if(!this.IsPostBack)
{
  this.resetButton.DataBind();
}
like image 76
bang Avatar answered Sep 16 '22 22:09

bang