修复asp.net中文本框的大小 [英] fix the size of textbox in asp.net
本文介绍了修复asp.net中文本框的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<asp:TextBox ID=txtComments runat="server" BorderColor="Gray"
BorderStyle="Solid" BorderWidth="1px" CausesValidation="true" Wrap="true"
MaxLength="100"
TextMode="MultiLine"
Width="350px">
在aspx.cs文件中
in aspx.cs file
public int MaxLength
{
get { return txtComments.MaxLength; }
set { txtComments.MaxLength = value; }
}
public void wordCount()
{
txtCount.Text = txtComments.MaxLength.ToString();
txtComments.Attributes.Add("onKeyUp", "javascript:document.getElementById(''" + txtCount.ClientID + "'').setAttribute(''value'', (" + txtComments.MaxLength + " - parseInt(document.getElementById(''" + txtComments.ClientID + "'').getAttribute(''value'').length)));");
}
我正在我的应用程序中编写以下代码..c有人能告诉我如何将光标固定在文本框中最后一个字符的末尾吗??
预先谢谢你.
[edit]添加了代码块-OriginalGriff [/edit]
i was writing following code in my application.. ccan anyone tell me that how can i fixed the cursor at the end of last character in textbox...?
thank you in advance.
[edit]Code blocks added - OriginalGriff[/edit]
推荐答案
这似乎总是一个好主意,但请确保您确实想要这个,因为这意味着用户只能使用退格键或键入键,如果他们在某个时候打错了字并不得不删除已经完成的所有操作,那将是很痛苦的.这也使用户无法突出显示任何文本并进行复制,这在很多情况下是无济于事的.但是,
如果您确实想执行此操作,则需要在以下事件上触发的一小段javascript:
This always seems like it ought to be a good idea but make sure you really want this because it means the user can only ever use backspace or type which if they make a typo at some point and have to delete all of what they have already done it can be a pain. It also stops the user being able to highlight any of the text and copy it which is very unhelpful in a lot of cases. However,
If you realy want to do this you will need a short bit of javascript that fires on the following events:
focus()
onKeyUp() //(after all other code)
onMouseUp()
并将光标设置到末尾只需执行以下操作:
this.value = this.value;
在javascript事件中,因为这会将(框内的)文本设置为自身,从而迫使光标重置到末尾.
and to set the cursor to the end simply do:
this.value = this.value;
in the javascript event as this will set the text (of the box) to itself thus forcing the cursor to be reset to the end.
这篇关于修复asp.net中文本框的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文