Hi i have a textbox which i am using as a counter to show how many characters are still allowed in another textbox. I have made it read only and its background transparent so that you cant tell it is a select box. The only problem is you can still click on it or tab to it. Is there a way to do this so it appears just like normal text and people cant click on it or tab to it?
If this is an Asp.Net Web Control set it's Enabled property to false
<asp:TextBox Enabled="false" />
If it is HTML you can do this:
<input type="text" disabled />
Just replace the input element with a span element or some other non-input element. This requires a trivial change to your JavaScript; you would assign to the innerHTML property of the element rather than value. Then the content will appear as normal text, and you can style it as desired.
you need some style with css and some trick with Jquery.
CSS
.readonly{
border:none;
background:#aaa;
}
Jquery
$(".readonly").focus(function(){
$(this).blur();
});
now just add class="readonly" to your textbox.
<asp:TextBox cssClass="readonly" />
check demo here .
Related
How can i change the mouse pointer of textbox in to hand symbol.
I am using Visual web Developer.
my intension is to have a textbox (with database value) to be placed inside the repeater's header division for allignment purpose.i made border style to none.
Thanks
just create one css and assign that css to textbox.
<style>
.txtclass{cursor:pointer;}
</style>
<asp:TextBox ID="txt" CssClass="txtclass" runat="server" />
That's it.
Hope it helps you.
EDIT :
<style>
.txtclass input[disabled="disabled"] {
// your color style
}
</style>
Try this.
<asp:ListBox
ID="ddlPA"
ClientIDMode="Static"
runat="server"
AutoPostBack="true"
SkinID="x"
CssClass="ListBoxCssClass"
SelectionMode="Multiple"
OnSelectedIndexChanged="ddlPA_SelectedIndexChanged">
</asp:ListBox>
When i select an item in asp:listbox , the selected item color changes to gray, i want to change the color to blue.
how can i do the same?
Recently searched for this and never found a reasonable solution so I created one with CSS only. I switched from a ListBox to a CheckBoxList and hid the checkbox.
In this example to keep it simple I just made the checkbox invisible for all items (option in CSS), and set the sibling text font-weight to 600 for the selected item (label in CSS) - you can CSS to your heart's desire once you have the selector setup correctly - background, pseudo :before image or border, etc. Keep in mind if you go with something before the item you can create spacing issues - I will include a CSS sample (after the first sample) for the "not checked" items so you can add padding/margin to make up for this offset. Lots of ways to do this but this will get you there until you feel like exploring other options.
ASPX:
<asp:CheckBoxList ID="chkList" CssClass="someclassname" runat="server" </asp:CheckBoxList>
CSS:
.someclassname input {display: none;}
.someclasssname input:checked + label {font-weight: 600;}
Personally I prefer line breaks and indents for CSS but easier reading here without.
Here is a CSS selector for the other non-checked items.
CSS:
.someclass input:not(:checked) + label {font-weight: 400;}
Again, we are hiding the checkbox and then formatting the text to the right of the checkbox. One additional nice feature here is that now a user can select multiple items with a touch based input device - no need for a ctrl or space key.
Also, unlike the ListBox, the CheckBoxList does not allow you to restrict the user to one selection. If you need this behavior then you can switch to a RadioButtonList.
You can set background colors from the .aspx page by specifying either the CssClass, or the BackColor property.. it looks like:
<asp:ListBox CssClass="MyListBox" BackColor="#e0e0e0"></asp:ListBox>
Setting the selected item is a little trickier... I don't believe there is an attribute for this directly. You can set it in javascript, or jQuery, something like:
<script type="text/javascript">
$(document).ready(function() {
$('#MyListBox').click(function() {
$("#MyListBox option:selected").css("background-color", "#e0e0e0");
});
});
</script>
So I have normal HTML table and inside it I have textbox.
<asp:TextBox runat="server" ID="txt1" CssClass="edit_mode_textbox" />
When I lower the textbox width, it's fine, but is there another solution?
This is only in IE9 and IE8.
Thanks!
There is nothing wrong with your asp:textbox or Table, its something wrong with background image you have set for this asp:textbox in your CSS. It may be repeating or you have been using 2 images in background. I am not certain about it unless you paste your CSS class edit_mode_textbox.
I hope this will answer your question, if yes please mark it as "answered".
apply css to remove some styles you do not need:
box-shadow:0;, border:none; and borde-radius:0;
I have a simple form in a ASPX page that have a lot of <label> and <asp:TextBox> pairing that construct the outlay of the form.
I have a requirement to add a string behind the textbox to indicate that the field is compulsory. I'd tried adding either a <span>, a <em> or a <div> after the field but it will still display the message at the bottom of the textbox.
Any way for me to achieve this?
EDIT:
I mean right hand side of the textbox, not behind as in watermark. My Bad.
EDIT for sample code:
I'd tried all the suggestion but it is still not working, thinking whether it's my code issue or not. Below are my codes:
<label>Telephone No.</label>
<asp:TextBox ID="txtTelNo" runat="server"></asp:TextBox>
<span class="afterInput">test</span>
any pointers? Thanks.
EDIT for Answer
As it turns out the problem lies in the css property. The template that i used has all the input assigned with the display: block property, which makes anything after the <input> element to be pushed down.
After creating a custom css class with display: inline-block and assign to them appropriately, i manage to get the result that i wanted.
Many thanks for the answer provided, especially the :after attributes and the watermark attributes.
See http://jsfiddle.net/ekWG9/
.required:after{
content: "*";
color: red;
}
<label>A box</label><input type="text" value="Hello" /><span class="required"></span>
<!-- alternative HTML -->
<span class="required"><label>A box</label><input type="text" value="Hello" /></span>
Using the :after pseudo element selector allows you to take the literal content out of the markup (e.g. you don't have to repeat "*" over and over).
You can also use relative or absolute positioning to tweak the location of the content of the :after pseudo element. Example: http://jsfiddle.net/ekWG9/1/
By behind the textbox, seems you are talking of watermark text.
You could use the TextBoxWatermark from ajaxcontrol toolkit.
There are also several jQuery alternatives to implement it.
html5 also has browser support for watermarks:
<input name="q" placeholder="Go to a Website">
You could add an attribute to your control to that effect.
Use css for this purpose:
span.clsRequired {
float:left;
margin:2px 0 0 3px;
color:red;
}
And your span before text box looks like:
<span class="clsRequired ">*</span>
you should try something like this
<body>
<form id="form1">
<asp:TextBox ID="TextBox1" runat="server"/> <span>Required field</span>
</form>
</body>
work on C# asp.net vs 05. I have a requirment, I have to fill text box with some data on gridview , which is coming from database and make it read-only
After that user can not enter any text on gridview template field. If I set textbox Enabled=false, then i lose text color, but i want to show text color. Just textbox to not be editable. I just want users to not be able to write anything in my textbox.
Isn't there a readonly property for the text box.
If then you can use
ReadOnly="true"
for the text box.
If you can use a label then I would prefer that one.
For wrapping contents inside a label you can use
word-wrap
word-wrap: break-word
Inside the properties choose your column field and in the properties.
Under Styles section
You can give a CssClass to the column.
If you specify CssClass as 'TextStyle'
the css looks like this
.TextStyle
{
color: #a9a9a9
}
In the color attribute give either the color name like 'red' or the hexcode like '#000000' for the text.
Enabled="false"
I'd use CSS to make a label look like a textbox.
Why does everyone insist on using an asp:label for this sort of thing? Just because it renders a <span> if you don't supply an AssociatedControlId?
You should look at using an asp:Panel or possibly an asp:Literal or asp:PlaceHolder for this as they will give you greater control over the output, and cleaner markup.
Panel would be better, as this will render the contents in a <div> rather than the PlaceHolder or Literal which won't add any extra markup.
The content you are putting in here is a semantic division, and so should really be marked up as such, and by default, <div>s are treated as a block display type, rather than as inline (<span>).
Here's a quick proof of concept I just knocked up.
<head runat="server">
<style>
.readTest
{
border: none;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox runat="server" Text="Do something" ReadOnly="true"
ID="txtOne" CssClass="readTest"></asp:TextBox>
</div>
</form>
</body>
</html>
Personally I would use a label, though you could write a custom control that renders a textbox or a label, depending on the state your app is in.
I'd prefer to write the text directly to the cell using a literal or String() output rather than using a control. It's a bit cleaner and will help minimize the amount of ViewState being written. Either that, or turn off ViewState for those controls being added.
Specify your CSS for the TextBox in the row created event of the GridView.