如何动态创建Sharepoint文本框(输入,类型=文本)多行? [英] How can I make a Sharepoint textbox (input, type=text) dynamically Multiline?

查看:142
本文介绍了如何动态创建Sharepoint文本框(输入,类型=文本)多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望Web部件上的文本框能够按需垂直增长.也就是说,除非用户为该行输入太多文本,否则它将是一行,这时它会自动换行并垂直增长以适应用户的冗长程度.

I want a textbox on my Web Part that will grow vertically on demand. That is, it will be one line unless the user enters too much text for that line, at which point it word wraps and grows vertically to accommodate the verbosity of the user.

我正在动态创建控件/元素,并且这样创建该元素:

I am creating my controls/elements dynamically, and I create this element like so:

boxPaymentExplanation = new TextBox()
{
    CssClass = "dplatypus-webform-field-input"
};
boxPaymentExplanation.Width = 660;
boxPaymentExplanation.Style.Add("display", "inline-block");

我尝试添加此行,以期实现此功能:

I tried adding this line, in the hopes of achieving this functionality:

boxPaymentExplanation.Style.Add("TextMode", "MultiLine");

...但是它对文本框的行为没有明显改变-我可以在文本中输入直到牛回到谷仓为止",但它只是将字符连续添加到文本框的末尾.它永远不会包裹,所以永远不会增长.

...but it makes no apparent change to the textbox's behavior - I can enter text into it "until the bovines come back to the barn" but it simply keeps adding the characters to the end of the textbox on a single row. It never wraps, so it never grows.

这是有效的jQuery(摘自Christopher Jennings提供的链接):

This is the jQuery that works (derived from the link that Christopher Jennings provided):

$(document).on("keyup", "[id$=explainPaymentTextBox]", function (e) {
    while ($(this).outerHeight() < this.scrollHeight + parseFloat($(this).css("borderTopWidth")) + parseFloat($(this).css("borderBottomWidth"))) {
        $(this).height($(this).height() + 1);
    };
});

...以及此C#:

boxPaymentExplanation = new TextBox()
{
    CssClass = "dplatypus-webform-field-input",
    ID = "explainPaymentTextBox"
};
boxPaymentExplanation.Width = 660;
boxPaymentExplanation.Style.Add("display", "inline-block");
boxPaymentExplanation.TextMode = TextBoxMode.MultiLine;

更新2

不幸的是,尽管上面的下降式jQuery可以动态扩展文本框,但是如果用户删除文本则无法使用;我希望它在发生这种情况时也能缩小...

UPDATE 2

Unfortunately, although the descent-into-the-mælström-esque jQuery above works for dynamically growing the textbox, it doesn't work if the user removes text; I would like it also to shrink when that happens...

推荐答案

您处在正确的轨道上.您需要将TextMode属性设置为Multiline.但是,您采用的方法是添加HTML标签属性,而不是设置.NET属性.只需将boxPaymentExplanation.Style.Add("TextMode", "MultiLine");替换为boxPaymentExplanation.TextMode = TextBoxMode.MultiLine;

You're on the right track. You need to set the TextMode property to Multiline. However, the approach you took is to add an HTML tag attribute rather than set the .NET property. Simply replace boxPaymentExplanation.Style.Add("TextMode", "MultiLine"); with boxPaymentExplanation.TextMode = TextBoxMode.MultiLine;

这篇关于如何动态创建Sharepoint文本框(输入,类型=文本)多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆