在运行时从C#向文本框添加属性

时间:2014-08-17 13:41:55

标签: c# asp.net twitter-bootstrap

我正在尝试在运行时将属性文本添加到文本框中,如下例所示。下面的代码有效,但属性仅在完整回发后生效,并且我会进行部分回发。

txtSKU1位于更新其他文本框的更新面板中,如DisplaySKUInfoClearSKUInfo函数中所示。这很有效 - 但是我试图添加的属性仅在完整回发之后才有效 - 有没有办法在不完整的情况下重新加载控件?

    protected void txtSKU1_TextChanged(object sender, EventArgs e)
    {
        if (sql.OpenConnection())
        {
            SKUInformation sku = sql.GetSKUInformation(txtSKU1.Text);

            if (sku.IsValid)
            {
                DisplaySKUInfo(sku.SKU, txtComp1, txtCost1, txtDescription1, txtMargin1);

                txtSKU1.Attributes.Remove("class");
                txtSKU1.Attributes.Remove("data-toggle");
                txtSKU1.Attributes.Remove("data-placement");
            }
            else
            {
                ClearSKUInfo(txtComp1, txtCost1, txtDescription1, txtMargin1);

                // These only work after a full postback
                txtSKU1.Attributes.Add("class", "popover-dismiss");
                txtSKU1.Attributes.Add("data-toggle", "popover");
                txtSKU1.Attributes.Add("data-placement", "top");
            }
        }
    }

1 个答案:

答案 0 :(得分:1)

我在这里看到的选项很少:

  1. 将txtSKU1移至UpdatePanel,它将自动更新。

  2. 使用ScriptManager.RegisterDataItem方法。

  3. 使用ScriptManager.RegisterStartupScript注册将为您设置这些属性的js。

相关问题