This question already has answers here:
Determine number of characters entered into textbox with C#
(4 answers)
Closed 8 years ago.
I would like to alert user about length of the mobile number which he has entered.
my textbox ID : txt1
my code behind :
if (txt1.txt.??? < 11)
{
alert;;;
}
please suggest me about tricks to perform this action.
thanks in advance.
To get the length of a textbox value from behind code.
if(txt1.Text.Length < 11)
{
//Your code here
}
else
{
//Your Code here
}
However, why don't you used a textbox masked extender like Ajax or a RegularExpressionValidator validation?
<asp:RegularExpressionValidator ID="RegularExpressionValidator2" runat="server" ErrorMessage="Enter valid Phone number" ControlToValidate="txt1" ValidationExpression="\d{10}" ValidChars="()-" ></asp:RegularExpressionValidator>
Related
This question already has answers here:
<input type="number"> not working in IE10
(6 answers)
Closed 4 years ago.
I have an HTML input control
<input id="textBox1" class="form-control" runat="server"/>
I add the following C# code to make it a Numeric updown control:
textBox1.Attributes["type"] = "number";
textBox1.Attributes["min"] = "0";
textBox1.Attributes["max"] = "50";
textBox1.Attributes["step"] = "1";
This is working fine in Chrome but in Internet Explorer the updown buttons are not displaying.
What should I do to display the buttons in IE also?
I know that a similar question has been asked here but I thought adding the Attributes in code behind could overcome this as suggested here in Sachin Gupta's answer.
See https://caniuse.com/#feat=input-number
Comment attached to IE versions is:
UI widget does not include increment/decrement buttons.
This question already has answers here:
Get the Value of an asp:HiddenField using jQuery
(8 answers)
Closed 5 years ago.
I assign a value to an ASP hidden field within the page load but can't access that value in my JQuery. I added an alert as a test and it comes up 'undefined'. Am I making a syntactic error?
<asp:HiddenField runat="server" id="hfID"/>
hfID.Value = "Test";
alert($('#hfID').Val());
Asp.Net Webforms mangles the id you give it to make sure it's unique on the page. You can use class as a selector or modify your jQuery selector so that it's looking for an id that ends in hfID.
$("[id$='hfID']")
This question already has answers here:
Tooltips for Button elements
(8 answers)
Closed 7 years ago.
I have this code on my project.
string="my string"
how i show this string on a button as a tool-tip. I want this to do programmatically. I want this to do in my code not the design.
i do my codings in asp.net with c# language
Here's how to add the tooltip programmatically
just get the id of the button
<asp:Button id="button1" Text="Submit" runat="server" />
in your code behind:
//do some code to retrieve data from database and store it to this variable
String tooltip = "some text";
button1.ToolTip = tooltip;
I'm having a strange problem with the Masked Edit Extender. I need to add a Mask and a Max Length Property to some text input at runtime according to a selected value of a Drop Down List. It works fine in almost all browsers, but in IE 8 and, according to another user, is also happening on IE 11, when I type an extra character that exceeds the Max Length, the current value of the text input gets erased and the New character typed Is captured erasing everything else.
I don't know what is the problem with these browser and if there is already a fix for that or I'm doing something wrong.
This is the big panorama:
When changing the option of the DropDownList I know the MaxLength and the Mask To Being Shown.
So my code is something like this (everything is inside of an update panel):
<asp:DropDownList ID="ddlCardType" runat="server" Width="334px" OnSelectedIndexChanged="ddlCardType_OnSelectedIndexChanged" AutoPostBack="true"></asp:DropDownList>
<asp:TextBox ID="txtAccountNumber" runat="server" CssClass="input" Width="328px" MaxLength="18"></asp:TextBox>
<asp:RequiredFieldValidator ID="rfvAccountNumber" runat="server" ControlToValidate="txtAccountNumber"
ErrorMessage="Type the account number">*</asp:RequiredFieldValidator>
<ajaxToolkit:MaskedEditExtender ID="meeAccountNumber" runat="server" TargetControlID="txtAccountNumber"
MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus" OnInvalidCssClass="MaskedEditError"
InputDirection="LeftToRight" ErrorTooltipEnabled="true" Mask="9999999999999999"
ClearMaskOnLostFocus="false" />
<ajaxToolkit:MaskedEditValidator ID="mevAccountNumber" runat="server" ControlExtender="meeAccountNumber"
ControlToValidate="txtAccountNumber" IsValidEmpty="false" InvalidValueMessage="Invalid Account"
Display="Dynamic" EmptyValueMessage="Account cannot be empty" ErrorMessage="Invalid Account" />
protected void ddlCardType_OnSelectedIndexChanged(object sender, EventArgs e)
{
List<crmBank> oListBanks = ViewState["oListBanks"] as List<crmBank>;
var oSelectedBank = oListBanks.Where(i => i.Id == ddlBank.SelectedValue).SingleOrDefault();
var oSelectedCard = oSelectedBank.CardList.Where(i => i.Id == ddlCardType.SelectedValue).SingleOrDefault();
LimitText(oSelectedCard.Length);
meeAccountNumber.Mask = oSelectedCard.Mask;
meeAccountNumber.EnsureValid();
}
private void LimitText(int characters)
{
txtAccountNumber.MaxLength = caracteres;
if (txtAccountNumber.Text.Trim().Length > txtAccountNumber.MaxLength)
{
txtAccountNumber.Text = string.Empty;
}
}
The current mask values that I'm having right now is
9999999999999999 (Max Length 16)
9999-9999-9999-9999 (Max Length 19)
9999-999999-9999 (Max Length 17)
I need to get the value for the Text Input with the mask so that's why I'm using ClearMaskOnLostFocus="false"
So in the first mask if my user types the character 17, for example 0123456789123456*7* all the value gets erased instead of the HTML max length property prevent the extra character typed so it stays in 0123456789123456, it becomes to just 7
Does anyone know what is happening or what can be happening and how I can make this works in all browsers?
I'm open to JQuery options or something like that. I just need to get the value according to a dynamic mask based on a dropDownList Value in case there is not a fix for this. But just remembering that the mask an max length will change dinamically so I need to do some ajax calls to get that values.
I know that I have to post what I have tried but, I think its an specific problem with the masked edit extender, because if I dont put a mask, the Max Length property resolved at runtime works as expected. It prevents for extra characters to be typed, so there must be something with that
Also The ajax toolkit version that I'm using was downloaded with nuget so I should have almost the most recent.
According to NUget I have the 7.0725. If I click on references a properties it says that the Version is : 3.5.7.725 And runtime version v2.0.50727
Thanks for your valuable help,
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Lost Focus method for asp.net textbox?
i want to check the data entered by user on the client side.
it is necessary for me to use control.
is there any way so that i can check after client move on to the next input and i can check the data by javascript ?
<asp:TextBox ClientIDMode="Static" onblur="return userCheck(this.id)" onkeyup="return userCheck(this.id)"
ID="txtUserName" runat="server" Width="180"></asp:TextBox>
here i have used two events but i want to use only one.
You can do that with onblur event using javascript.
f.e something like that:
<asp:TextBox runat="server" onblur="Javascript:alert('1234');" />
For what you want to do, you can set the textbox to have AutoPostBack=True; any time the text in the box is changed and the box loses focus, it will post back to the page; you can use the TextChanged property, as well, if you don't want to post back, which will check to see if the text of the TextBox has been changed between posts.
Finally, you can bind the JavaScript onFocus and onBlur events to the textbox, and handle changes to its contents via JavaScript:
http://support.microsoft.com/default.asp…
Source: http://answers.yahoo.com/question/index?qid=1006040618831