Automatically mark ASP.Net controls which have a RequiredFieldValidator on them - asp.net

Is there a clean and centralized way to automatically designate a background color or other CSS property for ASP.Net controls (i.e. a TextBox) with an enabled RequiredFieldValidator?
Currently I have manually set the background color of required controls to yellow. I would like to replace that with a central method so if the client requests a different color or marker or if a field's status changes from required to not or vice versa, I won't miss any of the controls.
Thanks
Update
This site is pre-compiled. Can something append a Css Class or other standards-compliant flag to items in the ControlToValidtate property at compile time?

Why not add a css class of required. You can have multiple classes on a single control by space delimiting them so imagine an input field which takes a number:
Now I can have two classes one which right aligns the text and one which handles the required field requirements.
Edit
One option before the page is rendered to walk through each control in the page, and if it's a required field validator, then find it's corresponding control and set the css property; however, this is a lot of work for somethign which you can tackle at design time.

Related

adding border around controls dynamically...asp.net

My ASP.NET application allows the user to create their own screens. They can, for example, drag controls like textboxes, combos, etc and place them on the desginer. Now, they want to group specific controls in a box. For example, all the Basic information such as User name, address, age ,DOB etc should be surrounded by a single box (like..group box control). The code on runtime, dynamically places all these controls to create a page.
I tried to achieve this using a Panel control with a black border. This works fine, but when I add a background color to the panel, I no longer see the controls inside the panel. They are hidden.
Is there any good to achieve this. Please help.

Adjust ASP button element font size

How can I implement a font-resize feature that also adjusts the text size of all ASP elements?
I'm part of a team that is working to implement an interactive course catalogue as a class project. The typical user for the site will be > 50, and one common request from surveys an interviews was to have a user-adjustable test size increase/decrease of not only the on-screen text, but the buttons, lists and other elements.
Another requirement for this class: everything has to be implemented in ASP.NET & C# 4.0.
According to the documentation, the object FontUnit controls the size and type style of ASP elements. We're going to be using a number of elements nested inside HTML divs, and would like some way for a single button click to implement a page-wide text size increase/decrease.
I tried
btnTextSize.Font.Size= FontUnit.Larger;
to test on a couple elements, but there was no change in size.
Try this:
http://www.white-hat-web-design.co.uk/blog/controlling-font-size-with-javascript/
It's javascript, but it may work for your needs.

Need to apply a css class to all textfields using Zend Framework

I'm doing some bit of redesigning here for which we hired an outsourced freelance designer. He sent in the designs however he's used css class styles for the textboxes as opposed to my earlier attempts to apply a ganeral style to the inputs tag which had its hiccups.
I've used the Zend View Helpers to create the textboxes however I would like a simpler way to be able to set it up so by default all textfields would have the base css class 'textfield' - is there a way to do so in code without me having to explicitly make the addition in every call made to the view helper?
If you want to apply this style to all textfields on your page you just need a general textfield style and there is no need to even touch your markup.
If you have other textfields as well which you want to style differently, you will have to either extend Zend_Form, Zend_Form_Element or Zend_Form_Element_Text. Probably it would be easiest to extend the former and adding an attribute 'class' with the value 'textfield' to every text element while looping through all form elements.
But again. Why would you need to touch your markup at all, you just need a style for textfields.

ASP.NET FileUpload - How to change the language of the "Browse..." button description?

I know the very similar question was posted here already (How to change the Text of the browse button in the FileUpload Control (System.Web.UI.WebControls)) and I understand it's not possible to change the description to some custom text, but isn't it at least possible to change it to a different language (e.g. to English)?
I'd like to do it so that my web page is whole in one language (because e.g. "Procházet..." instead of "Browse..." in the middle of English web page looks kind of weird to me).
This is determined at the browser level, unless you moved to something like a flash-based uploader (or <iframe> trickery), you can't customize it. Whatever language/localization the user's browser is in (usually based on the OS setting), that's the language they'll get on the "Browse..." button.
If your page is for consumers likely already in that language, then you're all set, the default behavior works. If people with another language setting come by, well...that's the language they picked, so it should be an intuitive button label, even if it doesn't match.
Although there is direct way to change the Caption of InputFile control,but you can always go for alternative way,
Add InputFile control to you page let's say "fileUpload" and make it Hidden or invisible.
Add new HTMLButton on form with Text Whatever you wanted to give it to your fileupload button (in addition you can also add TextBox too to show uploaded file name when events being gets handle at server side).
Onclick even of above button use below javascript
document.getElementById("fileUpload").click();
It will do the same thing without showing up default InputFile control.
No, it's a matter of client's operating system.

ASP.Net container control with multiple control collections

I've been trying to create a special kind of fieldset. Which does all kind of fantastic things, but mainly collapse and maintain state. Also the two parts of the fieldset (in the legend, and in the rest) must be available to code behind (declaratively).
The code in the consuming page or control should look something like this:
<myTagPrefix:Fieldset>
<myTagPrefix:Legend>[controls here should be available in codebehind]</myTagPrefix:Legend>
<myTagPrefix:Content>[controls here should be available in codebehind]</myTagPrefix:Content>
</myTagPrefix:Fieldset>
Or
<myTagPrefix:Fieldset>
<Legend>[controls here should be available in codebehind]</Legend>
<Content>[controls here should be available in codebehind]</Content>
</myTagPrefix:Fieldset>
Which would produce more-or-less the following HTML (excluding the magic collapsing and state-maintaining code):
<fieldset>
<legend>[result of rendered legend controls]</legend>
[result of rendered legend controls]
</fieldset>
I've looked into a templated control, exposing template container via properties marked as 'TemplateContainer', which works nice, except for the fact that the code behind cannot access the controls in the template anymore.
I also looked into inheriting a container control like panel, and override the render methods for the begin- and end-tag, which is also nice, except for that it can contain only one control collection, while this fieldset control should have two (the controls in the legend and the controls in the rest fieldset). This could be overcome by exposing the text of the legend as a property of the fieldset, but to keep things complicated, text is not the only thing to be displayed in the legend. (for instance: images and buttons can be displayed too).
This question can be seen more abstractly of course, I'm basically asking for a container control with multiple child control collections.
When I tried to figure out what to compare this with, the functionality comes close to a MultiView; a MultiView can only contain controls of Type 'View', and the controls of a View are available in code-behind. The fact that a MultiView does not restrict the number and uniqueness of its childcontrols, and my control should (a maximum of one legend, and one content element) is something I could live with ... for now ;)
Does anyone have an idea how the MultiView was built? Is there a trick I'm overlooking? Any help or suggestion would be appreciated.

Resources