I have a custom control which uses System.Windows.Form.Textbox as the underlying text box.
I want to change that type to type="number" however I don't see a way to do this.
The end goal is to have an input field which, when clicked on a smartphone browser, will give you only numeric keys to enter rather than the full keyboard.
It is possible to restrict the input to numbers only using JavaScript, but that is not what I want. I specifically need the keyboard to open with only numbers on it. If there is an alternative way to achieve this than setting type="number" then that should work as well.
You can add type="number" to an ASP.NET TextBox and it will render with that attribute.
<asp:TextBox ID="TextBox1" runat="server" type="number" />
Depending on ASP.NET version it will either render with both type="text" and type="number" (v2.0 - v3.5) or just type="number" (v4.0+).
If you wanted to add this conditionally in your code-behind, you could:
TextBox1.Attributes.Add("type", "number");
Related
I have something like this.
<input type="text">
I want enable/disable it based in certain variable value in server side.
I have tried this.
<input type="text" <%= DisableServiceInfo ? "disabled":"" %>/>
but not working.
I know this can be done.
<input type="text" disabled="<%= DisableServiceInfo ? "disabled":"invalid value" %>"/>
but this is not a valid mark-up. Because the only valid way to enable control is to remove disabled attribute.
I am not asking how value can be supplied based on variable but how attribute in injected
Please don't answer the ways to set it server side or by javascript. I just want to know if it is possible in this way?
Is this webforms? If you want to do this by the book, you can manually add an Id, and Runat="Server". Once you've done that, your control can be manipulated in your code-behind.
If your Id is ServiceInfo, you could do:
ServiceInfo.Attributes["disabled"] = "disabled";
I have two html input in one form, and I am setting them to required as follows:
<input id="email" name="textfield36" type="text" class="input3" runat="server" required="required" />
<input id="frEmail" name="textfield36" type="text" class="input3" runat="server" required="required" />
I need to set the Required attribute to false to one of the two inputs from c#. For example:
if (language == "English")
{
frEmail.Attributes.Add("required", "false");
}
else
{
email.Attributes.Add("required", "false");
}
This is causing an issue, because if the language is English, then the user only needs to fill the specified fields and the way it's happening now is that he's obliged to fill them all and vice versa. Note that on load I'm hiding the fields not relating to the language.
Can anyone help on this?
The required attribute is a Boolean attribute. That means the value is ignored. It's presence on the element all that matters. You need to remove the required attribute, not change its value.
email.Attributes.Remove("required");
I am using C# Asp.Net for creating a website. I have created an HTML5 date element in the web page. The date element is along with many other .Net elements (i.e textbox). I am unable to retrieve the value of date element.Below is my code
<asp:TextBox ID="TextBox10" runat="server"></asp:TextBox>
<input type="date" id="myDate" name="sel_date" value="YY-MM-DD" />
I have tried tried many methods from stackoverflow but nothing worked. i.e
1- String.Format("{0}", Request.QueryString["sel_date"]); // Not Working <br>
2- myDate.Value; <br><br>
I can get the value of textbox as its a .Net element but how can I get the value of Html5 Date element ?.
Try this code in .Aspx file
<input type="date" runat="server" id="myDate" name="sel_date" value="YY-MM-DD" />
and Access the value like this in .Aspx.cs file
String DOB = myDate.Value;
You will never get the value of HTML control directly in code behind.
Just a clarification to the above statement before it becomes "truth" :)
Yes, you can get any/all input field values, whether they are "server side control" or not (plain HTML <input />), from "code behind".
There is nothing wrong with this plain HTML5 <input /> field, it doesn't have to be a "server side" control:
<input type="date" id="myDate" name="sel_date" value="YY-MM-DD" />
It will be in the Request.Form collection on POSTback:
Request.Form["sel_date"];
Request["sel_date"];
The original code "didn't work" because it was looking for it in Request.QueryString["sel_date"]
Hth....
I would like to display asterisk instead of no value in password field.
When I am setting up the field as type=text then I can see the plain text. When I set the type as password then I am getting blank field.
Is there a way to display the value as asterisks?
<input type="text" id="txtPwd" runat="server" />
This is the field I have.
Thanks in advance, Laziale
You can use the HTML5 placeholder attribute:
<input type="password" placeholder="●●●●●●●●●">
Example: http://jsfiddle.net/AJ2kn/
If you want the user's text input to be replaced by asterisks you need to use a password input—a text input just won't do it:
<input type="password" id="txtPwd" runat="server" />
However, the default value will be blank (this applies to text input as well). If you want to initialize this to a default value, you can do it like this:
<input type="password" value="dummy" id="txtPwd" runat="server" />
Note: I highly recommend not putting a users' password as the default value of a password field! It may compromise your users' password.
If you want to display some asterisks as placeholder text when the field is empty you can do that with with the placeholder attribute (again, this applies to text input as well):
<input type="password" placeholder="*****" id="txtPwd" runat="server" />
I'm making a website with a login site where people can do different things.
When using an iPad to login the first letter in the password is auto set to uppercase, how do I change it so that the first letter is not uppercase, but standard lowercase or whatever they enter??
Try this:
<input type="password" ... autocapitalize="off">
This is straight from apple:
http://developer.apple.com/library/safari/#codinghowtos/mobile/userExperience/_index.html
Edit:
try just adding the autocapitalize tag to your asp:textbox, see if that works.
<asp:TextBox ID="txbPassWord" runat="server" TextMode="Password" autocapitalize="off"></asp:TextBox>
Try this inside your input tag (found in this question):
autocapitalize="off"
Note: If you are not using pure HTML (just noticed the ASP.NET tag) you will need to add this as an html parameter somehow depending on what control style you are using.
I assume you already did this:
You need to specify your input box to be of type "password".
<input type="password" name="password" />
I thought iOS Safari was smart enough to not do this for password tags, perhaps not though!