I have a text box that will allow the user to enter multiple authors by separate them with semicolon. Initially the Text Box is one line but after the user type in the first semicolon the text box will change to multiple line.
I’m able to change the text box to multiple line only if I click on “TAB” or “ENTER” keys. Is there any way to do it just by clicking on the semicolon key?
This is the partial front end code:
<!-- Report Author(s) Name(s) -->
<div class="row">
<div class="leftSide">
<asp:Label ID="LabelAuthorName" runat="server" Text="Author" />
</div>
<div class="rightSide">
<asp:TextBox ID="TextBoxAuthorName" runat="server" ToolTip="Author1; Author2; ...."
OnTextChanged="TextBoxAuthorName_TextChanged" AutoPostBack="True" ></asp:TextBox>
</div>
</div>
This is the partial back-end code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
TextBoxDocCreaDate.Text = DateTime.Now.ToString("D");
}
}
protected void TextBoxAuthorName_TextChanged(object sender, EventArgs e)
{
bool isSemicolonClick = false;
string context = TextBoxAuthorName.Text;
if (isSemicolonClick == false)
{
for (int i = 0; i < context.Length; i++)
{
if (char.Equals(context[i], ';'))
{
isSemicolonClick = true;
TextBoxAuthorName.TextMode = TextBoxMode.MultiLine;
}
}
}
}
You won’t really be able to trap that server-side unless you do a postback after each keystroke. Suggest using a simple JavaScript onkeypress event to check for semi-colons and go from there.
Then on your textbox, just call onkeypress=checkForSemiColor(event), if it equals 186 it’s a semi colon.