I have created dynamic checkbox with ID="chk" and I want to apply inline style to it. I tried
chk.Attributes.Add("style","opacity:1");
But it doesn't work as expected. It created span around check box and applies style to that.
But it works
chk.InputAttributes["style"] = "opacity:1";
But former works fine for TextBox. Why this complexity for different controls?
Update
As un-lucky answered, it is just an alternative that buries my real question i.e. Why this complexity for different controls?. Lets forget about style, think of any other atrribute. Why check box is different when it comes to Attribute.Add?
To add styles you have to try Style property instead for Attributes Following code will help you:
chkBox.Style.Add("opacity", ".3");
You can also try like this:
chkBox.Style["width"] = "70px";
chkBox.Style["height"] = "70px";
ASP.Net renders two <input> elements for checkboxes to overcome the fact that an unchecked checkbox is not POSTed.
I guess the easier approach is to assign CSS classes in code, and adjust your CSS to deal with the HTML details.
Related
I believe am in need of creating custom RichTextBox in C#. One kind of like that:
I admit it might not even have to be RichTextBox, but after some research I decided it's gonna be the easiest way. Functionality I need are icons at each row, checkboxes and text formatting. My program will process each line of the text and mark lines that are correct, incorrect, and strike out lines not necessary in further work, while showing line that's currently processed and allowing user to edit some lines freely (here: lines before Around 3 000 won't be editable, but those under the line will).
What's the problem then? I have no idea how to get it done. I've seen tutorial on how to make single-line textBox with icon or checkbox nearby, but I have no idea how to make both, and for multiline textBox (so I could freely scroll and everything would work fluently). I've read some questions on SO as well, but neither helped me.
I just don't know how to get started, I realize it won't be 5 min work, but I'm willing to do it. Until now I've been only able to create custom control deriving from RichTextBox, but I have no idea which methods and how to override. Any help appreciated.
Try to use WebBrowser control instead RichTextBox.
You can add CheckBoxes and editable content by setting a correct HTML code to it.
Set each TextBox or CheckBoxes ids and use GetElementsByTagName or GetElementById to access inner elements to get or set its attributes or values.
I already did some research and ended up with several autocomplete boxes which have one thing in common: they all match the whole expression which has been entered. Sometimes, they seem to be easily expandable, but at the end, they aren't.
However, I need a Textbox which allows the user to enter a word (e.g. "tag1"), displays a popup with some suggestions based on this single word, accept the suggestion with the return key and type in a new word (e.g "tag1 tag2") in the same textbox, with the popup popping up again. (I like the way CintaNotes handles this)
I need this for a tagging interface. It's often faster for the user to write the tags into a simple box, but sometimes, he needs assistance. This is what the autocomplete is for.
I've found some results, which don't work for my purpose (imho):
http://www.wpfpedia.com/item/details/743/wpf-autocomplete-textbox-control
http://www.codeproject.com/KB/WPF/WPF_Autocomplete.aspx
http://www.codeproject.com/KB/WPF/autocomplete_textbox.aspx
http://weblogs.thinktecture.com/cnagel/2011/01/autocomplete-textbox-with-wpf.html
Btw, I really like the way the Tag-Box for SO operates.
Does anyone have an idea? Is there a "out-of-the-box" - solution somewhere, which suits my needs but I didn't find? Or do I have to build one myself?
Thanks! :)
I think you mean a textbox which autocomplete for multiple words.
Like TokenizedTexbox on WPF Extended Toolkit.
this is the page: http://wpftoolkit.codeplex.com/wikipage?title=TokenizedTextBox&referringTitle=Home
Probably you would need to create your own Dictionary object of Key and Value pairs and hook that Dictionary to the textbox events and popup a suggestions dialog that displays the Value(s) from your Dictionary
Check this implementation out: http://code.google.com/p/kocontrols/downloads/list
You may inject your own Search algorithm and your own converter which converts the selected element to text, which you display in the TextBox. You will have to modify it slightly but I think that you might be able to solve your problem by basing your control on this implementation.
I never thought about this type of use case.
Can't you use different textboxes for the different tags? Something similar to how goole code does it?
If you have time, you can use the RichEditControl or TextBox and apply the same pattern used in Intellisense engine or Code Completation enabled editors: Hook the text changes events, Recogize context (last/current word) and display the options list on popup control. And optionally, on commit (detect acceptation or space key), apply the format to the word.
I am writing in asp.net c#.
I want a control similiar to RequiredFieldValidator except I want one of two fields to be required. I found an excellent example for two text fields but in my case one field is a check box and the other is an text box. If the check box is not checked the text box must be entered.
Any thoughts?
Just use javascript or C# code to check this.
I personally don't care for the RequiredFieldValidator types as they are limited and rather confusing.
With C# server side code you could just check
if (!chk.Checked && txtBox.Text.Length==0)
For JavaScript something to this effect:
if (!(document.getElementById('myCheckBox').Checked)
&& document.getElementByID('myTextBox').val=='')
You can always use the customvalidator if you have complex custom validation logic. This is probably your best way to go.
I've just started developing in Silverlight, and I have a calendar control which shows details for each day.
The text within the calendar is held within lots of textblocks, for some browsers the text size might be too big, so I want to have a slider control on the 'usercontrol' which allows the user to adjust the font size.
I'm building the calendar through c# code, so my question is.. what is the best way to 'wire' this up. I'm guessing it would be one of these options.
Add an event to the slider control for ValueChanged, then iterate through all TextBlocks setting the fontsize to the new size. This seems long-winded.
Maybe using a 'Style', which is attached to each TextBlock, then just changing the FontSize of the 'Style'.. ?? maybe ?
Using 'binding' & 'Dependancy Property'. I've looked into this, and it seems to be the way to do it, but I can't find an example where you're passing a value from one control to multiple other ones. Maybe I'm missing something.
I can do option 1 quite easily, but I want to learn about alternative methods of doing this.
Thanks
Rich.
A way to handle this is to not use fixed sizes but to size everything to its content. that way the control will get bigger when a larger font size is selected. Just like the TextBlock.
I've actually got this working now using option 3 which I'm happy with, it was very simple, but there seemed to be little documentation on it (maybe I was searching for the wrong thing).
It was as simple as adding a few lines...
Binding bind = new Binding("Value");
bind.Source = FontSlider;
The for every control that I want to apply the FontSlider's 'Value' to.. I do this...
MyTextBlock.SetBinding(TextBlock.FontSizeProperty,bind);
Simples.
Cheers
Rich.
I have to set dropdownlost to read only. I can set enabled =false. But I cannot set font color to regular dropdown text. It will show like blur. The samething I did textbox.readonly=false. There we can see font same as regular text, no change.
The same way I want read only for dropdownlist. Is there any way we can do with CSS or javascript or jQuery ?.
Thanks in advance
There is varying browser support for this. Typically, Internet Explorer provides fewer opportunities to override the default greyed out look for disabled controls, than the other main browsers. I have struggled to do this in the past across all browsers. I would be interested to see some answers here that do this rather than my advice not to do it...
I would question why you are doing this. Your users will be used to the default look of disabled controls. It is a visual cue to them that the control is disabled. I would urge you not to disrupt this subtle visual que that people are very very used to.
Unless you can give a compelling reason to do this of course.
One way to hack this would be to not disable the dropdown list at all (taking care of the styling). Then, add an event handler to the change event that sets the dropdown back to the original value. You would have to store the original value, probably in an input of type hidden, and when you handle the change event, first check whether the value is the same as the stored value. If not, set it back. If you don't make this check you will get an infinite loop, because setting it back to the original value will call the change event again.