为什么文本方向没有改变?

时间:2015-07-31 12:14:31

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

我正在尝试在selectIndexChanged下拉事件中更改文本框的方向(文本方向)但不起作用。

<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();");
        }

我正试图将其从左到右更改为&#39;从右到左&#39;

1 个答案:

答案 0 :(得分:0)

您应该能够使用Controls Style Property在事件处理程序中更改它;类似下面的内容

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