相关疑难解决方法(0)

我可以使用<%= ...%>在ASP.NET中设置控件属性吗?

<asp:TextBox ID="tbName" CssClass="formField" MaxLength="<%=Constants.MaxCharacterLengthOfGameName %>" runat="server"></asp:TextBox>
Run Code Online (Sandbox Code Playgroud)

上面的代码不起作用.我可以在后面的代码中设置文本框的MaxLength属性,但我宁愿不这样做.有没有我可以像前面那样在前端代码中设置MaxLength属性?

asp.net

6
推荐指数
3
解决办法
4227
查看次数

如何将枚举值设置为 Web 用户控件的自定义属性?

我们如何将枚举值绑定到 Web 用户控件的属性?我一直收到这个错误。

无法从“MyProperty”属性的字符串表示形式“MyEnum.MyValue”创建“MyEnum”类型的对象。

这是 MyWebUserControl.ascx.cs 背后的代码

[System.ComponentModel.Bindable(true)]
public MyEnum MyProperty { get; set; }
Run Code Online (Sandbox Code Playgroud)

SomeWebUserControl.ascx

<!-- This fails -->
<uc1:MyWebUserControl runat="server" ID="MyControl1"
    MyProperty="MyEnum.MyValue" />

<!-- This fails -->
<uc1:MyWebUserControl runat="server" ID="MyControl2" 
    MyProperty="<%# MyEnum.MyValue %>" />

<!-- This works -->
<uc1:MyWebUserControl runat="server" ID="MyControl3"
    MyProperty="0" />
Run Code Online (Sandbox Code Playgroud)

c# asp.net webforms

3
推荐指数
1
解决办法
3200
查看次数

标签 统计

asp.net ×2

c# ×1

webforms ×1