这有效:
<span value="<%= this.Text %>" />
Run Code Online (Sandbox Code Playgroud)
这不起作用:
<asp:Label Text="<%= this.Text %>" runat="server" />
Run Code Online (Sandbox Code Playgroud)
这是为什么?
如何使第二种情况正常工作,即将标签的文本设置为"文本"变量的值?
我试图使用以下代码基于用户的角色隐藏按钮:
<asp:Button ID="btndisplayrole" Text="Admin Button" Visible='<%= WebApplication1.SiteHelper.IsUserInRole("Admin") %>' runat="server" OnClick="DisplayRoleClick" />
Run Code Online (Sandbox Code Playgroud)
但是,当我运行上面的代码时,我收到以下错误消息:
无法从其字符串表示形式'<%= WebApplication1.SiteHelper.IsUserInRole("Admin")%>'为'Visible'创建'System.Boolean'类型的对象
这是我导航到的方式myPage.aspx,
<a href='~/myPage.aspx?show=<%#Eval("id")%>' id="showEach" runat="server">Show Each</a>
<a href="~/myPage.aspx?show=all" id="showAll" runat="server">Show All</a>
Run Code Online (Sandbox Code Playgroud)
我有一个gridview myPage.aspx
<asp:GridView ID="GridView1" runat="server">
<Columns>
<asp:BoundField HeaderText="ColumnOne" Visible="true"/>
<asp:BoundField HeaderText="ColumnTwo" Visible="true"/>
</Columns>
</asp:GridView>
Run Code Online (Sandbox Code Playgroud)
我想要做的是,如果查询字符串等于all(〜/ myPage.aspx?show = all),我想将GridView1的Column2可见性设置为true,否则,将visible设置为false.
我该怎么做 ?
我有一个自定义服务器控件,其属性为Title.使用控件时,我想在aspx页面中设置标题的值,如下所示:
<cc1:customControl runat="server" Title='<%= PagePropertyValue%>' >
more content
</cc1:customControl>
Run Code Online (Sandbox Code Playgroud)
但是,当我执行此操作时,我将显示正确的字符串<%= PagePropertyValue%>而不是我希望看到的属性值.
所以在尝试数据绑定表达式后(如下所示).我没有得到看起来很糟糕的字符串文字,但我也没有得到任何其他东西.
<cc1:customControl runat="server" Title='<%# PagePropertyValue%>' >
more content
</cc1:customControl>
Run Code Online (Sandbox Code Playgroud)
我需要对自定义控件做什么才能获得这种价值?或者我需要对页面做些什么.
我必须在这里做错事,但我找不到一个简单的方法让它工作.
想象一下以下代码:
<asp:RadioButtonList ID="MyRadioButtonList" runat="server">
<asp:ListItem Value="<%= CompanyName.SystemName.Constants.PaymentFrequency.FREQUENT.ToString() %>" Text="Yes" Selected="True"></asp:ListItem>
<asp:ListItem Value="<%= CompanyName.SystemName.Constants.PaymentFrequency.ONCE.ToString() %>" Text="No, Just do this once"></asp:ListItem>
</asp:RadioButtonList>
Run Code Online (Sandbox Code Playgroud)
但它不会在呈现页面之前编译语句.所以,如果我得到这个单选按钮列表中选择的值就包含有类似的"<%= COMPAN ...%>",而不是什么我的常量定义.
这个的正确语法是什么?
通过<%#some code%>和<%= some code%>在.aspx页面上执行绑定有什么区别吗?
例:
VS
谢谢.-Igor
我正在开发一个项目,我正在使用它<%= getString("key")%>来动态获取相应的文本.
当我在简单的p标签中使用它时,这很有用,但是我找不到使用Button/Label等控件的方法.
有什么办法,除了打电话
Mybutton.Text = getstring("key");
Run Code Online (Sandbox Code Playgroud)
动态添加文字?
我们的想法是getString检索af语言代码,并根据该代码获取适当语言的字符串.
我一直在环顾四周,但我遇到的只是在aspx页面中直接使用嵌入式代码标签,而不会将其剪切为buttontext.