0

I have created a user control. I want to use CSS classes in this, but no CSS is working here. I tried registering CSS in master page, user control. But nothing worked.

5
  • You have to provide with more details. Have you tried looking at the css references at run-time using FireBug or some similar tool? There shouldn't be much effort to use a control specific css style. Although I must say I disencourage you to do it. Commented Jan 20, 2012 at 8:04
  • yaa i have tried firebug but the class i create is shown blank....but in my stylesheet that class with some attributes exist Commented Jan 20, 2012 at 8:08
  • stackoverflow.com/q/34390/284240 Commented Jan 20, 2012 at 8:09
  • Have you refreshed the cache(STRG+F5)? Commented Jan 20, 2012 at 8:10
  • Ok, so the problem should be in the css file or in the way you use to reference it. Are you registering it in the header section? Commented Jan 20, 2012 at 8:24

1 Answer 1

0

As your usercontrol gets rendered in the containing page, you can use css on it like on any other tag on your website. The only thing you need to do is add the css file to the header of you masterpage.

When using css selectors tho, remember that the ID's of the controls on your usercontrol is not this one you should use as your css selector.

fe.

<input type='text' id='txtName'/>

in your usercontrol will be rendered to something like

<input type='text' id='ctl00_phMain_MyUserControl_txtName' /> 

so make sure you use the correct id to apply your style or use the class tag

Sign up to request clarification or add additional context in comments.

1 Comment

The ids will only get messed for server controls? He can use the CssClass attribute for server controls.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.