how to make a part of the textbox as readonly - c#

i have a tagtextbox on my page
when a user selects a category that category name goes to tagtextbox
now i want that this category name user cant change but he can append some more tags
means first tag becomes readonly and further he can add too in same text box

This is not possible.
Instead, you can put the first category name in a <span>, and put the textbox after the span.
You can then apply border: none to the textbox and make your own border around the entire thing to make it look like a single textbox.

CSS :
<style type="text/css">
.div {
margin:20px;
padding:10px;
background:#ccc;
float:left;
}
.textarea {
border:0;
display:block;
font-size:12px;
padding:5px 5px 0;
outline:none;
}
.span {
display:block;
background:#fff;
font-size:14px;
padding:5px 5px 5px;
color:green;
outline:none;
}
</style>
HTML :
<div class="div">
<div class="span">
<asp:TextBox runat="server" ID="txtNumber" BorderStyle="None" />
<asp:RegularExpressionValidator runat="server" ID="RegularExpressionValidator1" ValidationExpression="\d+" ControlToValidate="txtNumber" ErrorMessage="Only Numbers are allowed" Display="Dynamic" />
</div>
</div>

You can't make part of a textbox editable and another not.
My suggestion would be to change the type of element from a TextBox to a div or span via Javascript as soon as the user begins to enter the next tag.

If you want to allow append has in "paste" action, then you can't do that. Else and you just want to append via your code, why not use just a div to show what he has selected and add the selections to your post on a hidden textbox?

Adding to what SLaks said - Here is an example of a CSS & HTML hack where someone has added a span under the textbox. To make it look like it is part of the same textbox there is a border round the enclosing div. It looks quite effective.
textbox with uneditable name at the bottom

Related

How do I customize an asp:Button class?

How do I customize an asp:Button class?
This is like this proble: How to set css style to asp.net button? but not really since the button is inherited from a cs class.
I have this bit of code in an ASPX file:
<div class="buttonContainer" style="clear:both;width:100%;text-align:left">
<asp:Button ID="btnProceed" runat="server" Text="Next" OnClick="ProceedButton_Clicked" Enabled="true" />
</div>
So, if I want to make the button bigger or bolder text, how would I do it?
btnProceed is defined in a .cs file like this:
protected global::System.Web.UI.WebControls.Button btnProceed;
So, is there some way I can inherit a System.Web.UI.WebControls.Button class and change the font size?
All your server controls are ultimately going to render some HTML markup to the browser. So Apply a CSS class to your button and style it the way you want. You can use the CssClass property to set it.
<asp:Button ID="btnProceed" runat="server" Text="Hi" CssClass="yourClass" />
And put this style in your css file which is being included in your aspx page.
.yourClass
{
font-size:72px;
font-weight:bold;
}
You could be able to customize any style for your button with this
.buttonContainer input
{
font-size: 14px;
font-weight: bold;
/**** ETC ***** /
}
you can set Font Size at server-side by using btnProceed.Font.Size = FontUnit.Point(50);

How to make Dropdown List with checkboxes?

How do we make a drop down list with checkboxes? C# lang is preferred for this.
You can't. Not a real one anyway, but you can fake one by making a scrolling div which appears when you click a button (using JQuery):
<div id="cbListDiv" style="height: 172px; width:300px; overflow-y:scroll; border:1px solid silver; margin-top:8px;">
<asp:CheckBoxList id="cbList" runat="server" RepeatLayout="Flow" />
</div>
Then you'd need to add some code to display or expand that region when you click a link on the page. That's about as close as you can get I think.

Is there any alternative for <br /> in asp.net?

I was trying to display lblName1 and lblName2 only if they have text. Even when i dont have any value for lblName2, the break still has an impact. Can someone please advice me if there is any other way to display or conditionally display
<asp:Label ID="lblName1" runat="server" Visible= "false" ></asp:Label> <br />
<asp:Label ID="lblName2" runat="server" Visible= "false"> </asp:Label>
Thanks in advance..
Give the label a CSS class name and set the margin for that class:
<asp:Label ID="lblName1" CssClass="Testing123" runat="server" Visible= "false" ></asp:Label> <br />
.Testing123{ margin-bottom: 20px; }
If the Label is not rendered then no gap will be created.
You might consider adding a litteral to handle the br and this way play with its visibilty :
<asp:Literal runat=server Id=C_lit_Br><br /></asp:Literal>
with in your codebehind :
if (!lblName2.Visible)
C_lit_Br.Visible=false;
It is a quick patch, but it should work.
It is better to use literal in that case:
In literal text you also write html in it
wrap the labels in p tags:
<p><label1></p>
<p><label2></p>
Going with what you have and ignoring using any code behind changes, you can use some css to provide a break without using a <br /> tag.
By this, I mean if you were to give your <label> controls a css class, class="labelStyle
.labelStyle{
float: left;
clear: left;
}
Your html produced would look like
<span class="labelStyle">Some Text</span><span class="labelStyle">More Text</span>
If there is no value in the Labels, then your html would contain two empty span tags.
This will move the 2nd label onto the next line. However this may not fit in with the rest of your html, and because you are floating elements, then your overall layout might break.
An example is here http://jsfiddle.net/2v93f/

Making text box hidden in ASP.NET

I am using ASP.NET 3.5 and C#.
On my page I need to have a Text box that must not be visible to the user but it MUST be there when you look at the Page Source, reason being, another program called Eloqua will be looking at the page source and it must get the value of that text box.
The value of that text box will be populated based on what the user selects.
Thus, I cant set the text box property to Visible = False because then it will not be in the source HTML and I can't set the Enabled = False because I do not want the user to see the text box.
Is there some property I can use to make this text box hidden to the user but still visible in the page source?
My ASP.NET text box
<asp:TextBox ID="txtTester" runat="server"></asp:TextBox>
You can use a hidden field.
<asp:HiddenField id="myHiddenInput" runat="server" />
Use it just like a textbox.
Try this to invisible textbox instead of server side Visible property :
myTextBox.Style.Add("visibility", "hidden");
// or :
myTextBox.Style.Add("display", "none");
First thought: Can you use a hidden field? This would be much more suitable (<asp:hiddenfield ID="blah" runat="Server" /> if you want a .NET control).
If the app won't take that though you can actually just put "style='display: none;'" in the code-infront of the page. Intellisense won't like it, but it'll render just fine (EG: <asp:TextBox id="txtField" style="display: none;" runat="server" />)
Also from the codebehind you can do txtField.Attributes.Add("style", "display: none");
Or you could also just give it a CssClass "hidden" which in your CSS is defined as ".hidden { display: none;}"
The CSS class or just using a hidden field would be my recommendations.
Page.RegisterHiddenField or asp:HiddenField
CSS:
.hidden-div
{
display: none;
}
HTML:
<div class="hidden-div">
<input ... />
</div>
It will cause your input to be hidden, but it's gonna be visible in source code.
EDIT: Sorry, I misread it. I thought you wanted to hide an input. But it doesn't matter anyway, just replace input with basically anything.
If it must be a textbox for whatever reason just hide it with css:
<input type="text" name="blah" style="display:none" />
By Setting Visible = "false" in server side will not render the control. You should either use asp:Hidden or INPUT type="hidden". Other option is using CSS, by setting display:none.
Why not use a hidden field:
<input type="hidden" name="blah" />
How about using CSS to hide a div containing the text box:
.hidden {
position: absolute;
left: -9999px;
}
Then within your page:
<div class="hidden">
<asp:TextBox ID="TextBox1" runat="server" Text="hi"></asp:TextBox>
</div>
Hope this helps.
Simply, Try to create a CSS class and attach it to your TextBox as the following:
CSS Class Style
<style>
.Hide {
display:none;
}
</style>
Textbox using CssClass="Hide"
<asp:TextBox ID="txtTester" runat="server" CssClass="Hide"></asp:TextBox>
Note: you can't use validation with the Hidden control
<asp:TextBox ID="TextBox2" runat="server" visible="false"></asp:TextBox>

Anyway to dynamically set text in an asp:FileUpload?

When the user selects an item from a dropdownlist containing image names, I would like the FileUpload text box to be filled with a message I program such as "Replace this image with..." How would I do this?
Security restrictions in certain browsers (IE at least) prevent you from being able to actually set the text of an <input type="file" /> element, which is what the FileUpload ASP.NET control renders.
I am on a project where we are trying to manipulate the appearance of file upload elements, and it's proving to be quite difficult to do in a cross-browser-compliant manner. I suggest looking at flash-based solutions such as Uploadify, which is more customizable.
Due to the nature of the control, for security reasons you cannot manipulate it beyond some styling.
What you can do, however, is use a Flash or Silverlight based upload control. Or put your desired message in a label above the file input.
Not possible. The < input type="file" /> is part of the browser chrome. Some browsers don't show any text at all, so any solution would not be robust. As Bryan suggests, use a < label >.
Like others have said, there is no way to directly change the text of the file name box, but what you can do is create a label and use positioning to make sure the label appears directly above the uploader.
<span runat="server" id="SelectedFileSpan" style="position: absolute; top: 10px; left: 12px">
<asp:Label runat="server" ID="FileNameLabel"></asp:Label>
</span>
<asp:FileUpload runat="server" ID="FileUploader" />
Then set the text of the label.

Categories

Resources