ASP.net在线防爆pression问题 [英] ASP.net Inline Expression Issue

查看:87
本文介绍了ASP.net在线防爆pression问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎无法找出原因,这并不以下工作。我需要将文本框的值从行内前pression绑定。似乎是一个简单的事情吧?但这些都不能工作。有任何想法吗?先谢谢了。

 < ASP:文本框的id =tbName=服务器文本='<%#的eval(测试)%GT;' />
< ASP:文本框的id =tbName=服务器文本='<%=测试%GT;' />

编辑:
我应该指出,这个页面没有code后面,只在顶部以下指令。

 <%@导入命名空间=系统的%>
<%@导入命名空间=System.Web程序%>
<%@页面语言=C#%>

编辑:

这是我能想出短期增加了code背后的唯一可行的办法是增加一个内联服务器脚本,赞一个。我希望我知道为什么,除非你在数据绑定上下文是内联前pressions将无法工作。

 < SCRIPT LANGUAGE =C#=服务器>
   私人无效的Page_Load(对象发件人,发送System.EventArgs)
    {
      tbName.Text =测试;
    }
< / SCRIPT>


解决方案

在你在Page_Load将不得不作出的Page.DataBind()的调用

 < ASP:文本框的id =tbName=服务器文本='<%#的eval(测试)%GT;' />

工作

&下;%=%>是一个缩短回复于(),并且是从未有效作为属性,对于任何服务器标签

<%#%>可以使用,只有当conatainer是数据绑定(你的情况的页面)

<%$>可用于资源文件访问数据

编辑:您还可以看看<一个href=\"http://stackoverflow.com/questions/73484/how-to-bind-text-property-of-a-label-in-markup\">http://stackoverflow.com/questions/73484/how-to-bind-text-property-of-a-label-in-markup这是一个问题smimilar

I can't seem to figure out why this does not work below. I need to bind the text box to a value from an inline expression. Seems like a simple thing right? But neither of these work. Any ideas? Thanks in advance.

<asp:textbox id="tbName" runat="server" Text='<%# Eval("test") %>' />
<asp:textbox id="tbName" runat="server" Text='<%= "test" %>' />

Edit: I should mention that this page has no code behind and only the following directives at the top.

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Page Language="C#" %>

Edit:

The only workable solution that I could come up with short of adding a code behind is adding an inline server script, like this one. I wish I knew why the inline expressions won't work unless you're in a data binding context.

<script language="C#" runat="server"> 
   private void Page_Load(object sender, System.EventArgs e)
    {
      tbName.Text = "test";
    }
</script>

解决方案

In the Page_Load of you will have to make a call to Page.DataBind() for

<asp:textbox id="tbName" runat="server" Text='<%# Eval("test") %>' />

to work.

<%= %> is a shortened response.Write() and is never valid as an attribute, for any server tag.

<%# %> can be used, only if the conatainer is databound (the page in your case).

<%$ > can be used to access data in resources files.

EDIT: You can also take a look at http://stackoverflow.com/questions/73484/how-to-bind-text-property-of-a-label-in-markup which is a smimilar question.

这篇关于ASP.net在线防爆pression问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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