Widget CWidget CSS file

Widget with css file

Is style2d.css present under the /assets directory?

Also examine source code in the browser.

It’s safe to delete all content under /assets, it will be regenerated. (The browser cache may also need to be cleared.)


Make sure your .css file is not under any subfolder, as u stated.

Try this:

	protected function registerClientScript() {

        	$assetUrl = CHtml::asset(dirname(__FILE__).DIRECTORY_SEPARATOR);

		$cs = Yii::app()->getClientScript();



Kindly put any code inside the code block while posting. (its <> in the toolbar).

put your widget call inside the view _hellopart and call renderPartial like this:

    public function actionHello(){

	if(Yii::app()->request->isAjaxRequest)	{ 

		$data = array();

		$data["myValue"] = "I am coming from AJAX call!";

    		$this->renderPartial('_hellopart', $data, false, true); 

	} else { 

		$data = array();

		$data["myValue"] = "Intial Content loaded-";

		$this->render('hello', $data); }


let me check ur code again,

Btw, u should write the full path to the widget class if not in the same folder like this:




check u have got the correct path.

u see styles from with .css files works only if the .css file is registered inside the <head> tag.

Now u are doing a renderPartial() through AJAX and there registering the .css file. so, whats happening is, the .css file got registerd BUT its outside the <head> tag, with the data returned via AJAX call. Thus the styles are not applied.

U can do a check like this: call your widget in the hello.php, its is rendered using render() so the .css will get registered in the head & will style the elements.

What u can do is either place the styles within the view file or in some other .css file which loads with the page.

Also i found u gave wrong class name to the <div> in the widget logan.php view file.

//In the style2d.css its 

div.dtlHrd{ ... } 

//whereas in ur view its 

<div class="dtlHdr"> ... </div>

don’t forget to clear ur asstes folder first.

Cheers :)