【发布时间】:2012-03-09 20:56:58
【问题描述】:
我有一个根据 DropDownList 中的选择显示的 TextBox。文本框的默认行为是Visible="false"。 MaxLength 值需要根据 DropDownList 中的选择而变化。请注意,有时 TextBox 不会显示。
我在下面提供了标记。
<asp:UpdatePanel ID="updatePanel" runat="server" ChildrenAsTriggers="false" UpdateMode="Conditional" RenderMode="Inline">
<ContentTemplate>
<asp:DropDownList ID="ddlList" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlList_SelectedIndexChanged">
</asp:DropDownList>
<asp:TextBox ID="tbOther" runat="server" Visible="false" OnPreRender="tbOther_PreRender"></asp:TextBox>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="ddlList" />
</Triggers>
</asp:UpdatePanel>
我仍在努力解决这个问题,但是否可以将 MaxLength 的值保存在 DropDownList 上,然后在后面的代码中使用该值在 TextBox 上设置 MaxLength?由于我在 UpdatePanel 中有下拉菜单并且正在使用 AutoPostBack,因此这似乎应该是可能的,但我不知道如何/在何处存储该值。
【问题讨论】:
-
我认为使用JS设置文本框的最大长度而不是回发会更快更有效。