为什么<%=%GT; QUOT;&放大器;的标签,与放大器呈现LT;%=%GT;&安培; QUOT;? [英] Why do <%=%> tags render as "<%=%>"?

查看:143
本文介绍了为什么<%=%GT; QUOT;&放大器;的标签,与放大器呈现LT;%=%GT;&安培; QUOT;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个页面像这样的输入控制:

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%>");' />

当它被渲染

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

我用&LT;%=%GT; 页上的标签,但它呈现为

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

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

谁能告诉我为什么会这样?

Can anyone tell my why this is happening?

推荐答案

&LT;%=%>是只包含文字的HTML中可用,不能在服务器控件属性上使用

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

相反,你我们应该数据绑定&LT;%#%>,并在你的情况,我认为你正试图以触发客户端的JavaScript函数,然后你的code应该是这样的:

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) %>' />

和在服务器端,你应该结合本code(可能在Page.Load事件)的属性:

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();
}

这篇关于为什么&LT;%=%GT; QUOT;&放大器;的标签,与放大器呈现LT;%=%GT;&安培; QUOT;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆