【问题标题】:Why the direction of text is not getting changed ?为什么文本的方向没有改变?
【发布时间】:2015-10-23 02:52:28
【问题描述】:

我试图在下拉的 selectedIndexChanged 事件时更改文本框的方向(文本方向)但不起作用。

<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
             OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
            <asp:ListItem Text="Select" Selected="True"></asp:ListItem>
            <asp:ListItem Text="English" Value="Eng"></asp:ListItem>
            <asp:ListItem Text="Persian" Value="fa"></asp:ListItem>
        </asp:DropDownList>

JS:

<script type="text/javascript">
        function ChangeTextDirection()
        {
            document.getElementById("TextBox1").style.textAlign="right";
            return false;
        }
</script>

事件:

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

            DropDownList1.Attributes.Add("onchange", "ChangeTextDirection();");
        }

我正在尝试将其从“从左到右”更改为“从右到左”

【问题讨论】:

  • 设置样式“direction:RTL;”从右到左。
  • 但样式元素存在于客户端,但我必须从服务器端更改它,即 selectedIndexChanged 事件

标签: c# asp.net .net c#-4.0 webforms


【解决方案1】:

您应该能够在您的事件处理程序中更改它以及使用Controls Style Property;像下面的东西

 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
      this.TextBox1.Style["textAlign"] = "right";
    }

【讨论】:

    猜你喜欢
    • 2021-04-01
    • 1970-01-01
    • 2022-12-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-21
    • 2017-06-23
    相关资源
    最近更新 更多